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

Metpy StationPlot does not like dates #957

Closed
njmessina opened this issue Oct 15, 2018 · 1 comment · Fixed by #1130
Closed

Metpy StationPlot does not like dates #957

njmessina opened this issue Oct 15, 2018 · 1 comment · Fixed by #1130
Labels
Area: Plots Pertains to producing plots Type: Bug Something is not working like it should
Milestone

Comments

@njmessina
Copy link

Howdy...
I was trying to make a single station time series of sky condition using StationPlot. I get an error ('invalid type promotion') when I send a Pandas date index for the x-axis values. I emailed with Ryan and advised me to use date2num, which works flawlessly. He mentioned I should send some code for a possible bug fix.
Here's some sample code:

import numpy as np
import dateutil
import pandas as pd
import matplotlib.pyplot as plt
from matplotlib.ticker import FuncFormatter
import matplotlib.dates as mdates
import matplotlib.ticker as ticker
import matplotlib.dates as dates

from metpy.calc import reduce_point_density
from metpy.calc import wind_components
from metpy.cbook import get_test_data
from metpy.plots import add_metpy_logo, current_weather, sky_cover, StationPlot, wx_code_map
from metpy.units import units


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)) 

# This does NOT work:

x=  ts.index    # metpy does not like dates
stationplot = StationPlot(ax, x , y, fontsize=12)
stationplot.plot_symbol('C', ts , sky_cover)

# This works! :
#x= dates.date2num(ts.index)   # works!  ... Thank you Ryan!
#stationplot = StationPlot(ax, x , y, fontsize=12)
#stationplot.plot_symbol('C', ts , sky_cover)

ax.xaxis.set_major_locator(mdates.DayLocator())   
ax.xaxis.set_major_formatter(mdates.DateFormatter('%-d'))

plt.show()

 

Thank you!!

Joe

@dopplershift dopplershift added Type: Bug Something is not working like it should Area: Plots Pertains to producing plots labels Oct 16, 2018
@dopplershift dopplershift added this to the 0.10 milestone Oct 16, 2018
@dopplershift dopplershift modified the milestones: 0.10, 0.11 Dec 14, 2018
@zbruick
Copy link
Contributor

zbruick commented Jun 18, 2019

@dopplershift, how do you imagine this being handled? Is there a way to force any array to work here? Not sure if any others would give errors if we just handled the pandas case here. At any rate, the issue is within plot_text for this case, but the type conversion could likely be handled in the init function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Plots Pertains to producing plots Type: Bug Something is not working like it should
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants