Skip to content

Clean up High/Low Plotting Function A Bit #1234

@MethaneRain

Description

@MethaneRain

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions