From 43693180c747a4515a76a10d1f4ef1e67d2a4be9 Mon Sep 17 00:00:00 2001 From: Michael Levy Date: Tue, 10 Dec 2024 12:45:25 -0700 Subject: [PATCH] plt.scatter needs norm argument in Station 2 (#629) * plt.scatter needs norm argument in Station 2 Per a comment on the original PR to bring in the station 2 example, the colors weren't actually assigned based on the randomized values. * YAPF changes to pass CI --- .gitignore | 1 + Gallery/Station/NCL_station_2.py | 11 ++++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index b9fe7d3cb..7351c606e 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ .DS_Store .ipynb_checkpoints/ *.grd.gz +**/__pycache__/ diff --git a/Gallery/Station/NCL_station_2.py b/Gallery/Station/NCL_station_2.py index 4ea3322e4..a82c1bc10 100644 --- a/Gallery/Station/NCL_station_2.py +++ b/Gallery/Station/NCL_station_2.py @@ -57,8 +57,9 @@ nbins = len(colors) # One bin for each color -# Define colormap for plotting based on these colors +# Define colormap and norm for plotting based on these colors cmap = mpl.colors.ListedColormap(colors) +norm = mpl.colors.BoundaryNorm([-1.2] + bin_bounds + [35], len(colors)) ################################################### # Utility Function: Make Shared Plot: @@ -100,7 +101,12 @@ def make_shared_plot(title): zorder=0) # Scatter-plot the location data on the map - scatter = plt.scatter(lon, lat, c=dummy_data, cmap=cmap, zorder=1) + scatter = plt.scatter(lon, + lat, + c=dummy_data, + cmap=cmap, + norm=norm, + zorder=1) plt.title(title, fontsize=16, y=1.04) @@ -152,7 +158,6 @@ def make_shared_plot(title): # Add a horizontal colorbar cax = plt.axes((0.225, 0.05, 0.55, 0.025)) -norm = mpl.colors.BoundaryNorm([-1.2] + bin_bounds + [35], len(colors)) mpl.colorbar.ColorbarBase(cax, cmap=cmap, orientation='horizontal',