-
Hello, Firstly thank you for metpy 🙇 I'm following this example: https://unidata.github.io/python-training/workshop/Surface_Data/surface-data-with-siphon-and-metpy/ Lets say I have a temperature chart that looks something similar to the one on the bottom left here: I want to generate random points of text such as in this example here: I think the issue I have is that my longitude is much larger than my latitude for the plot I'm trying to construct, to make it similar to a widescreen aspect ratio. As I was hitting:
I came across a similar issue here which suggested to use I have the following code:
When I run it I hit the following error on the final line above:
Would someone be able to point me in the right direction? Thanks in advance for any help, I would be extremely grateful. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Hi @stackjohn, so you are looking to plot the value of some random grid point within your domain and overlay that on a color filled contour map? If so, here is a minimum working example to do a random choice of lat/lon points (with replacement). You should be able to replace the generated arrays with those from a gridded file pretty easily to choose the random points. There will likely be a bit more work to get the values from the array at those points, but not too hard. Hope this helps! import cartopy.crs as ccrs
from metpy.plots import StationPlot
import numpy as np
import matplotlib.pyplot as plt
# Assuming latitude values between 30 and 60N every 1 degree
lats = np.arange(30, 60, 1)
# Assuming longitude values between -140 and -60 every 1 degree
# converted into 0 to 360 range.
lons = np.arange(360-140, 360-60, 1)
# Making fake values
values = np.random.random(10)*45
# Randomly choosing lat/lon points using numpy
rlats = np.random.choice(lats, size=10)
rlons = np.random.choice(lons, size=10)
# Plotting an example figure
fig = plt.figure(1, figsize=(10, 8))
ax = plt.subplot(1, 1, 1, projection=ccrs.PlateCarree())
points = StationPlot(ax, rlons, rlats, transform=ccrs.PlateCarree())
points.plot_parameter('C', values)
ax.coastlines()
plt.show() |
Beta Was this translation helpful? Give feedback.
-
@kgoebber thank you for taking the time to do this and provide a working example. Very much appreciated. |
Beta Was this translation helpful? Give feedback.
Hi @stackjohn, so you are looking to plot the value of some random grid point within your domain and overlay that on a color filled contour map?
If so, here is a minimum working example to do a random choice of lat/lon points (with replacement). You should be able to replace the generated arrays with those from a gridded file pretty easily to choose the random points. There will likely be a bit more work to get the values from the array at those points, but not too hard. Hope this helps!