diff --git a/metpy/plots/_mpl.py b/metpy/plots/_mpl.py index 025a64b107c..6640e2c7f9f 100644 --- a/metpy/plots/_mpl.py +++ b/metpy/plots/_mpl.py @@ -273,7 +273,9 @@ def get_datalim(self, transData): # noqa: N803 """ full_transform = self.get_transform() - transData - XY = full_transform.transform(np.vstack((self.x, self.y)).T) # noqa: N806 + posx = self.convert_xunits(self.x) + posy = self.convert_yunits(self.y) + XY = full_transform.transform(np.vstack((posx, posy)).T) # noqa: N806 bbox = transforms.Bbox.null() bbox.update_from_data_xy(XY, ignore=True) return bbox diff --git a/metpy/plots/tests/baseline/test_symbol_pandas_timeseries.png b/metpy/plots/tests/baseline/test_symbol_pandas_timeseries.png new file mode 100644 index 00000000000..f6cba4a1c62 Binary files /dev/null and b/metpy/plots/tests/baseline/test_symbol_pandas_timeseries.png differ diff --git a/metpy/plots/tests/test_station_plot.py b/metpy/plots/tests/test_station_plot.py index 7193935d104..3de38536d3d 100644 --- a/metpy/plots/tests/test_station_plot.py +++ b/metpy/plots/tests/test_station_plot.py @@ -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, @@ -341,3 +342,20 @@ 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=0, 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