[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[python #DCS-251943]: MetPy time series plots



Greetings!

You can actually accomplish this using MetPy's `StationPlot` class. A basic 
example of using this for a standard 2D plot is here:

  
https://unidata.github.io/MetPy/latest/examples/plots/Station_Plot.html#sphx-glr-examples-plots-station-plot-py

and the full documentation of this class is here:

  
https://unidata.github.io/MetPy/latest/api/generated/metpy.plots.StationPlot.html#metpy.plots.StationPlot

`StationPlot` works just fine for plotting on any axis coordinates, not just 
spatial, so you can use it with standard matplotlib timeseries plots, as done 
in this example code:

    from datetime import datetime, timedelta
    import matplotlib.pyplot as plt
    from metpy.plots import StationPlot, current_weather
    import numpy as np

    # Create some dummy data, including WMO codes for current weather
    cur_wx_codes = [65, 85, 95, 99, 54, 57, 59, 67, 88, 82, 79, 75]
    dummy_y_vals = np.zeros(len(cur_wx_codes))  # only to place on plot
    dates = [datetime.utcnow() + timedelta(hours=i) for i in 
range(len(cur_wx_codes))]
    temps = np.random.randn(len(dates)) * 10 + 70

    # Create a plot using matplotlib's StationPlot
    fig = plt.figure()
    ax = fig.add_subplot(1, 1, 1)
    sp = StationPlot(ax, dates, dummy_y_vals)
    ax.plot(dates, temps)
    sp.plot_symbol('C', cur_wx_code, current_weather, fontsize=16, color='red')

Hope this helps,

Ryan

> I have ASOS csv data that I read into a dataframe and turn into a series of
> time series plots (see attachment called ops.asos.202002070440.kbgm.png).
> 
> I'd like to modify the last time series plot in the image (Precip) by
> adding in hourly weather condition symbols along the bottom as in the
> attached gempak image (gempak_timeseries_with_currentWeatherSymbols.pdf).
> 
> Are there MetPy utilities that might help me do this?



Ticket Details
===================
Ticket ID: DCS-251943
Department: Support Python
Priority: Low
Status: Closed
===================
NOTE: All email exchanges with Unidata User Support are recorded in the Unidata 
inquiry tracking system and then made publicly available through the web.  If 
you do not want to have your interactions made available in this way, you must 
let us know in each email you send to us.