I have two 2D arrays, each of them representing a property on a map. One of them represents hail probability (0%-100%) and the othe one hail severity (0-No Hail, 1-Low, 2-Medium, 3-High).
I can plot this arrays separately with matplotlib's imshow and a predefined colormap:
import matplotlib.pyplot as plt
import matplotlib.colors as cl
cmap = cl.ListedColormap(['#00FF00', '#FFFF00', '#FF0000'])
bounds = [0, 30, 60, 100]
norm = cl.BoundaryNorm(bounds, cmap.N)
plt.subplot(121)
plt.imshow(hail_prob, cmap=cmap, norm=norm)
cmap = cl.ListedColormap(['#00FF00', '#FFFF00', '#FF0000'])
bounds = [0.5, 1.5, 2.5, 3.5]
norm = cl.BoundaryNorm(bounds, cmap.N)
plt.subplot(122)
plt.imshow(hail_sev, cmap=cmap, norm=norm)
This is quite easy as seen above.
However I want a unique plot that combines both features. I have tested the contour function, but the data is quite irregular and the plots look quite bad.
I have been thinking about combining both characteristics into one colormap, but I'm not quite sure about how to do it. Let's say that I want a colour for each combination of probability and severity.
Any ideas on how to do this?
I would do a scatter plot, where the color is one value, and the size is another. For example, the color could be probability but size would be intensity.
Here is some random data
hail_prob = np.random.rand(48, 64)
hail_sev = np.random.randint(0,4,hail_sev.shape)
And here, from your existing data you can grab x-y points with np.meshgrid and use them in the scatter plot:
x = np.arange(hail_prob.shape[1])
y = np.arange(hail_prob.shape[0])
xy = np.meshgrid(x,y)
scatter(*xy, c=hail_prob, s=hail_sev)
You'll have to tweak the normalization on the sizes, because your units will be something different from a good pixel size.

Or for a more interesting shape:

I'm not sure how this will turn out but you could use different colormaps and overlay one plot on top of the other and play with the alpha (transparency) of the top one.
Say,
cmap1='Reds'
cmap2='Blues'
plt.imshow(hail_prob, cmap=cmap1, norm=norm)
plt.imshow(hail_sev, cmap=cmap2, norm=norm, alpha=0.5)
plt.colorbar()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With