Skip to content

Commit

Permalink
Add test for pandas timeseries as valid x in StationPlot
Browse files Browse the repository at this point in the history
  • Loading branch information
zbruick committed Aug 22, 2019
1 parent 6886e79 commit 6e1ab33
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -52,7 +52,7 @@ matrix:
include:
- python: 2.7
env:
- VERSIONS="numpy==1.12.0 matplotlib==2.0.0 scipy==0.17.0 pint==0.8 xarray==0.10.7"
- VERSIONS="numpy==1.12.0 matplotlib==2.0.0 scipy==0.17.0 pint==0.8 xarray==0.10.7 pandas==0.20.0"
- TASK="coverage"
- TEST_OUTPUT_CONTROL=""
- python: "3.7-dev"
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions metpy/plots/tests/test_station_plot.py
Expand Up @@ -7,6 +7,7 @@
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import pytest

from metpy.plots import (current_weather, high_clouds, nws_layout, simple_layout,
Expand Down Expand Up @@ -341,3 +342,21 @@ def test_barb_unit_conversion_exception(u, v):
stnplot = StationPlot(ax, x_pos, y_pos)
with pytest.raises(ValueError):
stnplot.plot_barb(u, v, plot_units='knots')


@pytest.mark.mpl_image_compare(tolerance={'1.5': 0.0, '1.4': 0.0}.get(MPL_VERSION, 0.000),
savefig_kwargs={'dpi': 300}, remove_text=True)
def test_symbol_pandas_timeseries():
"""Test the usage of Pandas DatetimeIndex as a valid `x` input into StationPlot."""
pd.plotting.register_matplotlib_converters()
rng = pd.date_range('12/1/2017', periods=5, freq='D')
sc = [1, 2, 3, 4, 5]
ts = pd.Series(sc, index=rng)
fig, ax = plt.subplots()
y = np.ones(len(ts.index))
stationplot = StationPlot(ax, ts.index, y, fontsize=12)
stationplot.plot_symbol('C', ts, sky_cover)
ax.xaxis.set_major_locator(matplotlib.dates.DayLocator())
ax.xaxis.set_major_formatter(matplotlib.dates.DateFormatter('%-d'))

return fig

0 comments on commit 6e1ab33

Please sign in to comment.