Skip to content

Commit

Permalink
remove plot function
Browse files Browse the repository at this point in the history
  • Loading branch information
mbeale committed Nov 9, 2019
1 parent c558c63 commit 85ced60
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 95 deletions.
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
numpy
requests
pandas
matplotlib
sphinx
8 changes: 1 addition & 7 deletions timeseriesql/tests/timeseries_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,10 +460,4 @@ def test_invalid_index(self):
# out of bounds stop date index
out_of_bounds_date = np.datetime64(int(t1.time[0] - 86400), "s")
new_t = t1[out_of_bounds_date:np.timedelta64(3, "m")]
self.assertEqual(len(new_t), 0)

def test_matplotlib(self):
t1, t2, t3 = self.basic_timeseries

t1.plot(legend=True)
self.assertEqual(1, len(plt.get_fignums()))
self.assertEqual(len(new_t), 0)
87 changes: 0 additions & 87 deletions timeseriesql/timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -604,93 +604,6 @@ def rolling_window(self, size, stepsize=1):
collection.chunks = (TimeChunk(slice(i, i+size), slice(None, None, None)) for i in range(0, len(self)-size+1, stepsize))
return collection

def plot(self, ax=None, legend=True, **kwargs):
"""Plot charts using sane time series defaults with Matplotlib.
Parameters
----------
ax : matplotlib.axes.Axes
an Axes to plot against. One will be created if not included
legend: Boolean
Decision to generate a legend
Returns
-------
None
Example
-------
cpu.plot()
>>>
"""

import matplotlib.pyplot as plt
from matplotlib.dates import (
DayLocator,
HourLocator,
MonthLocator,
YearLocator,
MinuteLocator,
DateFormatter,
)

date_index = self.time.dt
if ax is None:
fig = plt.figure(1)
fig.autofmt_xdate()
ax = fig.add_subplot(111)

window = (date_index[-1] - date_index[0]).astype(int)

xlabel = ""
if window <= 3600:
minor_locator = MinuteLocator()
minor_formatter = DateFormatter("%M")
major_locator = HourLocator()
major_formatter = DateFormatter("\n%Y-%m-%d %H:%M")
xlabel = "Minute"
elif window <= 86400:
minor_locator = HourLocator()
minor_formatter = DateFormatter("%H:%M")
major_locator = DayLocator()
major_formatter = DateFormatter("\n%Y-%m-%d")
xlabel = "Hour"
elif window <= (7 * 86400):
minor_locator = HourLocator(interval=6)
minor_formatter = DateFormatter("%H:%M")
major_locator = DayLocator()
major_formatter = DateFormatter("\n%Y-%m-%d")
xlabel = "Hour"
elif window <= (60 * 86400):
interval = 1
if len(date_index) > 30:
interval = 2
minor_locator = DayLocator(interval=interval)
minor_formatter = DateFormatter("%m-%d")
major_locator = YearLocator()
major_formatter = DateFormatter("\n%Y")
xlabel = "Day"
else:
minor_locator = MonthLocator()
minor_formatter = DateFormatter("%B")
major_locator = YearLocator()
major_formatter = DateFormatter("\n%Y")
xlabel = "Month"

ax.xaxis.set_minor_locator(minor_locator)
ax.xaxis.set_minor_formatter(minor_formatter)
ax.xaxis.set_major_locator(major_locator)
ax.xaxis.set_major_formatter(major_formatter)
ax.fmt_xdata = DateFormatter("%Y-%m-%d %H:%M:%S")

ax.set_title(self._generate_title(), fontsize=18)
ax.set_xlabel = xlabel
# OPTION: plot each stream separate axs?
# OPTION: markers/events/annotations
ax.plot(date_index, self.data, **kwargs)
if legend:
labels = self._generate_labels()
ax.legend(title="Streams", labels=labels[:5])

def copy(self):
"""Override the copy method to include the labels
Expand Down

0 comments on commit 85ced60

Please sign in to comment.