Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix: too many xticks #89

Merged
merged 1 commit into from
Feb 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions pysep/recsec.py
Original file line number Diff line number Diff line change
Expand Up @@ -1326,6 +1326,26 @@ def get_y_axis_positions(self):

return y_axis

def get_x_axis_tick_values(self):
"""
Determine, based on the length of the plotted traces, how often tick
marks should be applied so that they are spaced as aesthetically
pleasing values.
"""
# Get a rough estimate for total length of time of the trace in seconds
if self.xlim_s:
rs_len = self.xlim_s[1] - self.xlim_s[0]
else:
# Assuming that all waveforms are trimmed to the same length
rs_len = self.st[0].stats.endtime - self.st[0].stats.starttime

# Find order of magnitude of the length to give a rough estimate
oom = np.floor(np.log10(rs_len))
xtick_major = 10 ** oom
xtick_minor = xtick_major / 2

return xtick_minor, xtick_major

def process_st(self):
"""
Preprocess the Stream with optional filtering in place.
Expand Down Expand Up @@ -1459,6 +1479,12 @@ def plot(self, subset=None, page_num=None, **kwargs):

# Change the aesthetic look of the figure, should be run before other
# set functions as they may overwrite what is done here
_xtick_minor, _xtick_major = self.get_x_axis_tick_values()
# Use kwarg values to avoid double inputs of the same parameter
if "xtick_minor" not in self.kwargs:
self.kwargs["xtick_minor"] = _xtick_minor
if "xtick_major" not in self.kwargs:
self.kwargs["xtick_major"] = _xtick_major
self.ax = set_plot_aesthetic(ax=self.ax, **self.kwargs)

# Partition the figure by user-specified azimuth bins
Expand Down