Unidata / MetPy

MetPy is a collection of tools in Python for reading, visualizing and performing calculations with weather data.
https://unidata.github.io/MetPy/
BSD 3-Clause "New" or "Revised" License
1.23k stars 408 forks source link

Clean up High/Low Plotting Function A Bit #1234

Open MethaneRain opened 4 years ago

MethaneRain commented 4 years ago

The High Low function introduced in the MSLP 1000-500mb Thickness plotting example is a wonderful touch to Python graphics. I thought maybe adding a black outline to the text would help it pop a bit more.

ex:

With matplotlib.patheffects and outline_effect = [patheffects.withStroke(linewidth=2.5, foreground='black')]

I also added an ax argument to the code so it could be imported as an external library and plot to the current axes.


def plot_maxmin_points(ax, lon, lat, data, extrema, nsize, symbol, color='k',
                       plotValue=True, transform=None):
       import numpy as np
       from matplotlib import patheffects
       from scipy.ndimage.filters import maximum_filter, minimum_filter
       outline_effect = [patheffects.withStroke(linewidth=2.5, foreground='black')]

       mxy, mxx = np.where(data_ext == data)
       #print(mxy,mxx)

       for i in range(len(mxy)):
          A = ax.text(lon[mxy[i], mxx[i]], lat[mxy[i], mxx[i]], symbol, color=color, size=24,
                    clip_on=True, horizontalalignment='center', verticalalignment='center',
                    transform=transform)
          A.set_path_effects(outline_effect)
          B = ax.text(lon[mxy[i], mxx[i]], lat[mxy[i], mxx[i]]-0.66,
                    str(np.int(data[mxy[i], mxx[i]])),
                    color=color, size=12, clip_on=True, fontweight='bold',
                    horizontalalignment='center', verticalalignment='top', transform=transform)
          B.set_path_effects(outline_effect)

Since adding an outline pushes the pressures too close to the symbol I gave it some space, there's probably a more accepted way but this worked for me in my case.

lon[mxy[i], mxx[i]], lat[mxy[i], mxx[i]]-0.66

Thought I would pass my 2 cents on!

Sample Image:

Source code for my HiLo

dopplershift commented 4 years ago

I think this seems like some nice improvements. I'd be interested in seeing a PR go in to update the example.

We could also look at incorporating the extrema-finding and the plotting as functions in MetPy.

MethaneRain commented 4 years ago

We could also look at incorporating the extrema-finding and the plotting as functions in MetPy.

I figured it would be good place to have it since it seems to work and adds a nice graphic to surface and upper mb plots

eliteuser26 commented 4 years ago

I would make a suggestion for the Hi/Low feature. The red colour does show well with the black highlight but it is hard to read the dark blue colour and black highlight. I would suggest a lighter blue colour with the black highlight to make easier to read.