Skip to content

Commit

Permalink
Another try, another cook in the stew
Browse files Browse the repository at this point in the history
  • Loading branch information
taldcroft committed Feb 3, 2022
1 parent f70a27f commit 055c8c1
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions Ska/Matplotlib/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def remake_ticks(ax):
ticklocs = set_time_ticks(ax)
ax.figure.canvas.draw()

def plot_cxctime(times, y, fmt=None, fig=None, ax=None, yerr=None, xerr=None,
def plot_cxctime(times, y, fmt=None, fig=None, ax=None, yerr=None, xerr=None, tz=None,
state_codes=None, interactive=True, **kwargs):
"""Make a date plot where the X-axis values are in a CXC time compatible format. If no ``fig``
value is supplied then the current figure will be used (and created
Expand All @@ -123,6 +123,7 @@ def plot_cxctime(times, y, fmt=None, fig=None, ax=None, yerr=None, xerr=None,
:param fig: pyplot figure object (optional)
:param yerr: error on y values, may be [ scalar | N, Nx1, or 2xN array-like ]
:param xerr: error on x values in units of DAYS (may be [ scalar | N, Nx1, or 2xN array-like ] )
:param tz: timezone string
:param state_codes: list of (raw_count, state_code) tuples
:param interactive: use plot interactively (default=True, faster if False)
:param ``**kwargs``: keyword args passed through to ``plot()`` or ``errorbar()``
Expand All @@ -137,16 +138,14 @@ def plot_cxctime(times, y, fmt=None, fig=None, ax=None, yerr=None, xerr=None,
if ax is None:
ax = fig.gca()

dates = cxctime2plotdate(times)
args = () if fmt is None else (fmt,)

if yerr is not None or xerr is not None:
if fmt is not None:
kwargs.update({'fmt': fmt})
ax.errorbar(cxctime2plotdate(times), y, yerr=yerr, xerr=xerr, **kwargs)
ax.errorbar(dates, y, yerr, xerr, *args, **kwargs)
else:
times = CxoTime(times).datetime64
if fmt is not None:
ax.plot(times, y, fmt, **kwargs)
else:
ax.plot(times, y, **kwargs)
ax.plot(dates, y, *args, **kwargs)
ax.xaxis_date(tz)

ticklocs = set_time_ticks(ax)
fig.autofmt_xdate()
Expand All @@ -158,7 +157,7 @@ def plot_cxctime(times, y, fmt=None, fig=None, ax=None, yerr=None, xerr=None,

# If plotting interactively then show the figure and enable interactive resizing
if interactive and hasattr(fig, 'show'):
fig.canvas.draw()
fig.canvas.draw_idle()
ax.callbacks.connect('xlim_changed', remake_ticks)

return ticklocs, fig, ax
Expand Down

0 comments on commit 055c8c1

Please sign in to comment.