def format_contour_axes(ax): """ Format the axes limits, tick marks, and tick labels for the contour plots Args: ax (:class: 'matplotlib.Axes'): The set of axes to be manipulated """ # Use geocat.viz.util convenience function to set axes tick values gvutil.set_axes_limits_and_ticks(ax=ax, xlim=(-180, 180), ylim=(-90, 90), xticks=np.arange(-180, 181, 30), yticks=np.arange(-90, 91, 30)) # Use geocat.viz.util convenience function to add minor and major ticks gvutil.add_major_minor_ticks(ax, labelsize=8) # Use geocat.viz.util convenience function to make plots look like NCL # plots by using latitude, longitude tick labels gvutil.add_lat_lon_ticklabels(ax) # Remove the degree symbol from tick labels ax.yaxis.set_major_formatter(LatitudeFormatter(degree_symbol='')) ax.xaxis.set_major_formatter(LongitudeFormatter(degree_symbol='')) # Use geocat.viz.util convenience function to set titles and labels gvutil.set_titles_and_labels(ax, maintitle='300mb', maintitlefontsize=8)
def make_bar_plot(ax, dataset): years = list(dataset.time.dt.year) values = list(dataset.values) colors = ['blue' if val < 0 else 'red' for val in values] ax.bar(years, values, color=colors, width=1.0, edgecolor='black', linewidth=0.5) ax.set_ylabel('Pa') # Use geocat.viz.util convenience function to add minor and major tick lines gvutil.add_major_minor_ticks(ax, x_minor_per_major=4, y_minor_per_major=5, labelsize=8) # Use geocat.viz.util convenience function to set axes tick values gvutil.set_axes_limits_and_ticks(ax, xticks=np.linspace(1980, 2000, 6), xlim=[1978.5, 2003.5]) return ax
def __init__(self, *args, **kwargs): # Set class defaults self._default_height = 8 self._default_width = 10 # TODO: address all input arguments and run checks # Pull out title arguments self.maintitle = kwargs.get('maintitle') self.lefttitle = kwargs.get('lefttitle') self.righttitle = kwargs.get('righttitle') # Pull out axes info self.xlim = kwargs.get('xlim') self.ylim = kwargs.get('ylim') # Make sure x and y limits specified (for now) #TODO: make x and y limits self-determinable somehow if self.xlim is None or self.ylim is None: raise AttributeError( "For now, xlim and ylim must be specified as kwargs") # Pull out tick arguments if specified self.xticks = kwargs.get('xticks') self.yticks = kwargs.get('yticks') # Pull out axes label arguments self.xlabel = kwargs.get('xlabel') self.ylabel = kwargs.get('ylabel') # pull out colorbar arguments self.colorbar = kwargs.get('colorbar') # Set up figure self._set_up_fig() # Set up axes with projection if specified if kwargs.get('projection') is not None: self.projection = kwargs.get('projection') self.ax = plt.axes(projection=self.projection) self.ax.coastlines(linewidths=0.5, alpha=0.6) else: self.ax = plt.axes() # TODO: un-hardcode set_axes_limits_and_ticks(self.ax, xlim=self.xlim, ylim=self.ylim, xticks=self.xticks, yticks=self.yticks) # Set specified features if kwargs.get('show_land') is True: self.show_land() if kwargs.get('show_coastline') is True: self.show_coastline() if kwargs.get('show_lakes') is True: self.show_lakes()
def radar_plot(X, Y, values, bg_color=None): # Create a figure and axes using subplots fig, ax = plt.subplots(figsize=(6, 8)) # Choose default colormap cmap = gvcmaps.gui_default # Plot using contourf p = plt.contourf(X, Y, values, cmap=cmap, levels=np.arange(-20, 70, 5) * 100, zorder=3) # Change orientation and tick marks of colorbar plt.colorbar(p, orientation="horizontal", ticks=np.arange(-15, 65, 15) * 100, drawedges=True, aspect=12) # Use geocat.viz.util convenience function to add minor and major tick lines gvutil.add_major_minor_ticks(ax, labelsize=12) # Use geocat.viz.util convenience function to add titles to left and right of the plot axis. gvutil.set_titles_and_labels(ax, lefttitle=ds.DZ.long_name, lefttitlefontsize=16, righttitle=ds.DZ.units, righttitlefontsize=16, xlabel="", ylabel="") # Use geocat.viz.util convenience function to set axes limits & tick values gvutil.set_axes_limits_and_ticks(ax, xlim=(-240, 240), ylim=(-240, 240), xticks=np.arange(-200, 201, 100), yticks=np.arange(-200, 201, 100)) # Use geocat.viz.util convenience function to set tick placements gvutil.add_major_minor_ticks(ax, x_minor_per_major=5, y_minor_per_major=5, labelsize=14) # Set aspect ratio ax.set_aspect('equal') # Allow optional background circle to be set if (bg_color is not None): circle_bg = plt.Circle((0, 0), 240, color=bg_color, zorder=1) ax.add_artist(circle_bg) # Show plot plt.show()
def Plot(color, row, col, pos, title): # Generate axes, using Cartopy, drawing coastlines, and adding features projection = ccrs.PlateCarree() ax1 = plt.subplot(row, col, pos, projection=projection) ax1.coastlines(linewidths=0.5) ax1.add_feature(cfeature.LAND, facecolor="lightgray") # Import an NCL colormap newcmp = color # Contourf-plot data hgt = t.plot.contourf(ax=ax1, transform=projection, levels=40, vmin=100, vmax=1600, cmap=newcmp, add_colorbar=False) # Add color bar cbar_ticks = np.arange(100, 1600, 100) cbar = plt.colorbar(hgt, orientation='vertical', shrink=0.8, pad=0.05, extendrect=True, ticks=cbar_ticks) cbar.ax.tick_params(labelsize=10) # Use geocat.viz.util convenience function to set axes parameters without calling several matplotlib functions # Set axes limits, and tick values gvutil.set_axes_limits_and_ticks(ax1, xlim=(0, 90), ylim=(0, 90), xticks=np.linspace(-180, 180, 13), yticks=np.linspace(-90, 90, 7)) # Use geocat.viz.util convenience function to make plots look like NCL plots by using latitude, longitude tick labels gvutil.add_lat_lon_ticklabels(ax1) # Use geocat.viz.util convenience function to add minor and major tick lines gvutil.add_major_minor_ticks(ax1, labelsize=12) # Use geocat.viz.util convenience function to set titles and labels without calling several matplotlib functions gvutil.set_titles_and_labels(ax1, maintitle=title, maintitlefontsize=16, righttitlefontsize=14, xlabel="", ylabel="")
def make_contour_plot(ax, dataset): lat = dataset['lat'] lon = dataset['lon'] values = dataset.data # Import an NCL colormap cmap = gvcmaps.BlWhRe # Specify contour levelstamam v = np.linspace(-0.08, 0.08, 9, endpoint=True) # The function contourf() produces fill colors, and contour() calculates contour label locations. cplot = ax.contourf(lon, lat, values, levels=v, cmap=cmap, extend="both", transform=ccrs.PlateCarree()) p = ax.contour(lon, lat, values, levels=v, linewidths=0.0, transform=ccrs.PlateCarree()) # Label the contours ax.clabel(p, fontsize=8, fmt="%0.2f", colors="black") # Add coastlines ax.coastlines(linewidth=0.5) # Use geocat.viz.util convenience function to add minor and major tick lines gvutil.add_major_minor_ticks(ax, x_minor_per_major=3, y_minor_per_major=4, labelsize=10) # Use geocat.viz.util convenience function to set axes tick values gvutil.set_axes_limits_and_ticks(ax, xticks=[-60, -30, 0, 30], yticks=[40, 60, 80]) # Use geocat.viz.util convenience function to make plots look like NCL plots, using latitude & longitude tick labels gvutil.add_lat_lon_ticklabels(ax) return cplot, ax
def Plot(color, row, col, pos, title): # Generate axes, using Cartopy, drawing coastlines, and adding features projection = ccrs.PlateCarree() ax1 = plt.subplot(row, col, pos, projection=projection) ax1.coastlines(linewidths=0.5) ax1.add_feature(cfeature.LAND, facecolor="lightgray") # Import an NCL colormap newcmp = color #gvcmaps.BlAqGrYeOrRe # Contourf-plot data t.plot.contourf(ax=ax1, transform=projection, levels=40, vmin=100, vmax=1600, cmap=newcmp, cbar_kwargs={ "orientation": "vertical", "ticks": np.arange(100, 1600, 100), "label": "", "shrink": 0.8 }) # Use geocat.viz.util convenience function to set axes parameters without calling several matplotlib functions # Set axes limits, and tick values gvutil.set_axes_limits_and_ticks(ax1, xlim=(0, 90), ylim=(0, 90), xticks=np.linspace(-180, 180, 13), yticks=np.linspace(-90, 90, 7)) # Use geocat.viz.util convenience function to make plots look like NCL plots by using latitude, longitude tick labels gvutil.add_lat_lon_ticklabels(ax1) # Use geocat.viz.util convenience function to add minor and major tick lines gvutil.add_major_minor_ticks(ax1, labelsize=12) # Use geocat.viz.util convenience function to set titles and labels without calling several matplotlib functions gvutil.set_titles_and_labels(ax1, maintitle=title, maintitlefontsize=16, righttitlefontsize=14, xlabel="", ylabel="")
def Plot(color, row, col, pos, title): # Generate axes, using Cartopy, drawing coastlines, and adding features projection = ccrs.PlateCarree() ax1 = plt.subplot(row, col, pos, projection=projection) ax1.coastlines(linewidths=0.5) ax1.add_feature(cfeature.LAND, facecolor="lightgray") # Import an NCL colormap newcmp = color # Contourf-plot data t.plot.contourf( ax=ax1, transform=projection, levels=40, vmin=0, vmax=32, cmap=newcmp, cbar_kwargs={ "orientation": "vertical", "extendrect": True, "ticks": np.arange(0, 32, 2), "label": "", "shrink": 0.8}) # Use geocat.viz.util convenience function to set axes parameters without calling several matplotlib functions # Set axes limits, and tick values gvutil.set_axes_limits_and_ticks( ax1, xlim=(30, 120), ylim=(-60, 30)) # Use geocat.viz.util convenience function to set titles and labels without calling several matplotlib functions gvutil.set_titles_and_labels( ax1, maintitle=title, maintitlefontsize=14, xlabel="", ylabel="")
def Plot(color, row, col, pos, title): # Generate axes, using Cartopy, drawing coastlines, and adding features projection = ccrs.PlateCarree() ax1 = plt.subplot(row, col, pos, projection=projection) ax1.coastlines(linewidths=0.5) ax1.add_feature(cfeature.LAND, facecolor="lightgray") # Import an NCL colormap newcmp = color # Contourf-plot data temp = t.plot.contourf(ax=ax1, transform=projection, levels=40, vmin=0, vmax=32, cmap=newcmp, add_colorbar=False) # Add color bar cbar_ticks = np.arange(0, 32, 2) cbar = plt.colorbar(temp, orientation='vertical', shrink=0.8, pad=0.05, extendrect=True, ticks=cbar_ticks) cbar.ax.tick_params(labelsize=10) # Use geocat.viz.util convenience function to set axes parameters without calling several matplotlib functions # Set axes limits, and tick values gvutil.set_axes_limits_and_ticks(ax1, xlim=(30, 120), ylim=(-60, 30)) # Use geocat.viz.util convenience function to set titles and labels without calling several matplotlib functions gvutil.set_titles_and_labels(ax1, maintitle=title, maintitlefontsize=14, xlabel="", ylabel="")
def format_linegraph_axes(ax): """ Format the axes limits, tick marks, and tick labels for the line graphs Args: ax (:class: 'matplotlib.Axes'): The set of axes to be manipulated """ # Use geocat.viz.util convenience function to set axes tick values gvutil.set_axes_limits_and_ticks( ax=ax, xlim=(-90, 90), ylim=(-20, 50), xticks=np.arange(-90, 91, 30), yticks=np.arange(-20, 51, 10), xticklabels=['90S', '60S', '30S', '0', '30N', '60N', '90N']) # Use geocat.viz.util convenience function to add minor and major ticks gvutil.add_major_minor_ticks(ax, x_minor_per_major=3, y_minor_per_major=5, labelsize=12)
def make_shared_plot(title): # Generate figure (set its size (width, height) in inches) and axes using Cartopy projection plt.figure(figsize=(10, 5.5)) ax = plt.axes(projection=ccrs.PlateCarree()) # Use geocat.viz.util convenience function to add minor and major tick lines gvutil.add_major_minor_ticks(ax, x_minor_per_major=4, y_minor_per_major=5, labelsize=14) # Use geocat.viz.util convenience function to make plots look like NCL plots by using latitude, longitude tick labels gvutil.add_lat_lon_ticklabels(ax) # Use geocat.viz.util convenience function to set axes limits & tick values without calling several matplotlib functions gvutil.set_axes_limits_and_ticks(ax, xlim=(-125, -70), ylim=(25, 50), xticks=range(-120, -75, 20), yticks=range(30, 51, 10)) # Turn on continent shading ax.add_feature(cartopy.feature.LAND, edgecolor='lightgray', facecolor='lightgray', zorder=0) ax.add_feature(cartopy.feature.LAKES, edgecolor='white', facecolor='white', zorder=0) # Scatter-plot the location data on the map scatter = plt.scatter(lon, lat, c=dummy_data, cmap=cmap, zorder=1) plt.title(title, fontsize=16, y=1.04) return scatter, ax
# Add a text box to indicate the pressure level props = dict(facecolor='white', edgecolor='none', alpha=0.8) ax.text(105, 52.7, '500hPa', transform=projection, fontsize=18, ha='center', va='center', color='mediumorchid', bbox=props) # Use geocat.viz.util convenience function to set axes tick values gvutil.set_axes_limits_and_ticks(ax, xticks=[100, 120, 140], yticks=[20, 30, 40, 50]) # Use geocat.viz.util convenience function to make plots look like NCL plots by using latitude, longitude tick labels gvutil.add_lat_lon_ticklabels(ax) # Use geocat.viz.util convenience function to add minor and major tick lines gvutil.add_major_minor_ticks(ax, x_minor_per_major=4, y_minor_per_major=5, labelsize=18) # Use geocat.viz.util convenience function to add main title as well as titles to left and right of the plot axes. gvutil.set_titles_and_labels(ax, lefttitle="Temp", lefttitlefontsize=20,
# Plot with linear y axis: # Generate figure (set its size (width, height) in inches) and axes plt.figure(figsize=(8, 8)) ax = plt.axes() # Use geocat.viz.util convenience function to add minor and major tick lines gvutil.add_major_minor_ticks(ax, x_minor_per_major=5, y_minor_per_major=4, labelsize=14) # Use geocat.viz.util convenience function to set axes parameters gvutil.set_axes_limits_and_ticks(ax, xlim=(-20, 40), ylim=(1000, 0), xticks=np.arange(-20, 60, 10), yticks=np.arange(0, 1200, 200)) # Use geocat.viz.util convenience function to set titles and labels gvutil.set_titles_and_labels(ax, maintitle='Profile Plot', xlabel=U.long_name, ylabel=U['lev'].long_name) # Add reference line x=0 ax.axvline(x=0, color='black', linewidth=0.5) # Plot data plt.plot(U20.data, U20.lev,
# Plot curves that bound the region to be colored plt.plot(TS.lat, top, color='SlateBlue') plt.plot(TS.lat, bottom, color='SlateBlue') # Fill the area between the bounds ax.fill_between(TS.lat, top, bottom, color='SlateBlue') # Use geocat.viz.util convenience function to add minor and major tick lines gvutil.add_major_minor_ticks(ax, x_minor_per_major=3, y_minor_per_major=4, labelsize=14) # Use geocat.viz.util convenience function to set axes parameters gvutil.set_axes_limits_and_ticks( ax, ylim=(220, 320), xlim=(-90, 90), xticks=np.arange(-90, 91, 30), xticklabels=['90S', '60S', '30S', '0', '30N', '60N', '90N']) # Use geocat.viz.util convenience function to set titles and labels gvutil.set_titles_and_labels( ax, maintitle="A Title with $\\eta\epsilon\lambda\\alpha\sigma$ Characters", ylabel=TS.long_name) # Draw sigma on axes ax.text(0.15, 0.15, "$\sigma$", fontsize=40, transform=ax.transAxes) plt.show()
data2 = generate_2d_array((ny, nx), 10, 10, -28., 15., 1) data3 = generate_2d_array((ny, nx), 10, 10, -25., 18., 2) ############################################################################### # Create figure and axes using gvutil fig, axs = plt.subplots(1, 3, figsize=(12, 6), sharex='all', sharey='all', gridspec_kw={'wspace': 0}) # Use geocat.viz.util convenience function to set axes tick values gvutil.set_axes_limits_and_ticks(axs[0], xticks=np.arange(0, 120, 20), yticks=np.arange(0, 120, 20), xticklabels=np.arange(0, 100, 20), yticklabels=np.arange(0, 100, 20)) # Use geocat.viz.util convenience function to add minor and major tick lines gvutil.add_major_minor_ticks(axs[0], x_minor_per_major=4, y_minor_per_major=4) # Specify which edges of the subplot should have tick lines axs[0].tick_params(axis='both', which='both', left=True, right=False) # Force subplot to be square axs[0].set_aspect(aspect='equal') # Repeat for other subplots with a few changes gvutil.set_axes_limits_and_ticks(axs[1], xticks=np.arange(0, 120, 20), yticks=np.arange(0, 120, 20), xticklabels=np.arange(0, 100, 20), yticklabels=np.arange(0, 100, 20))
edgecolor='lightgray', facecolor='lightgray', zorder=0) # Draw the key for the quiver plot as a rectangle patch ax.add_patch( plt.Rectangle((155, 65), 25, 25, facecolor='white', edgecolor='black', zorder=1)) # Use geocat.viz.util convenience function to set axes tick values gvutil.set_axes_limits_and_ticks(ax, xticks=range(-180, 181, 30), yticks=range(-90, 91, 30)) # Use geocat.viz.util convenience function to add minor and major tick lines gvutil.add_major_minor_ticks(ax, labelsize=12) # Use geocat.viz.util convenience function to make plots look like NCL plots by using latitude, longitude tick labels gvutil.add_lat_lon_ticklabels(ax) # Use geocat.viz.util convenience function to add titles to left and right of the plot axis. gvutil.set_titles_and_labels(ax, lefttitle=ds['U'].long_name, righttitle=ds['U'].units) # Add timestamp ax.text(-200, -115, f'Created: {datetime.now()}')
xdata, ydata = np.meshgrid(xlist, ylist) zdata = np.random.normal(0, 3.0, size=(31, 31)) ############################################################################### # Create figure plt.figure(figsize=(10, 10)) # Create axes ax = plt.axes() # Use geocat.viz.util convenience function to set axes limits & tick values without calling several matplotlib functions gvutil.set_axes_limits_and_ticks(ax, xlim=(0, 30), ylim=(0, 30), xticks=None, yticks=None, xticklabels=None, yticklabels=None) # Use geocat.viz.util to add major and minor tics gvutil.add_major_minor_ticks(ax, x_minor_per_major=5, y_minor_per_major=5, labelsize=18) # Use geocat.viz.util convenience function to add titles to left and right of the plot axis. gvutil.set_titles_and_labels(ax, ylabel="wave number", labelfontsize=24) # Set ticks and labels only on left and top of plot ax.xaxis.tick_top()
# Set 0 level contour line to a thicker linewidth # If you try to access the "levels" attribute of cs (cs.levels), # the list of levels is: [-6, -4, -2, 0, 2, 4, 6, 8, 10] # level 0 is at the 3rd index of that list, so those contour lines # can be accessed at cs.collections[3] cs.collections[3].set_linewidth(1) # Label the contour levels -4, 0, and 4 cl = ax.clabel(cs, fmt='%d', levels=[-4, 0, 4]) # Use geocat.viz.util convenience function to set axes limits & tick values gvutil.set_axes_limits_and_ticks(ax, xlim=[100, 220], ylim=[0, 1.55 * 1e16], xticks=[135, 180], yticks=np.linspace(0, 1.55 * 1e16, 7), xticklabels=['135E', '180'], yticklabels=np.linspace(0, 180, 7, dtype='int')) # Use geocat.viz.util convenience function to add minor and major tick lines gvutil.add_major_minor_ticks(ax, x_minor_per_major=3, y_minor_per_major=3, labelsize=16) # Use geocat.viz.util convenience function to add titles gvutil.set_titles_and_labels(ax, maintitle="Pacific Region", maintitlefontsize=20, lefttitle="Velocity Potential",
'Nov', 'Dec' ] ############################################################################### # Plot: fig, axs = plt.subplots(2, 2, figsize=(12, 8), gridspec_kw=dict(wspace=0.25)) x = np.arange(len(months)) # where to draw x ticks width = 0.2 # width of each bar within the groups # Create the subplots using a loop panel = 0 for row in range(0, 2): for col in range(0, 2): # Use geocat.viz.util convenience function to set axes parameters gvutil.set_axes_limits_and_ticks(axs[row][col], ylim=(0.4, 1.2), xticks=x, yticks=np.arange(0.4, 1.4, 0.2), xticklabels=months) # Use geocat.viz.util convenience function to add minor and major tick lines gvutil.add_major_minor_ticks(axs[row][col], x_minor_per_major=1, y_minor_per_major=4, labelsize=12) # Use geocat.viz.util convenience function to set titles and labels gvutil.set_titles_and_labels(axs[row][col], ylabel='(\u00B0C)', labelfontsize=14) # Add overall figure title fig.suptitle('Paneling bar plots, dummy data', size=20, y=0.94)
U = ds.U ############################################################################### # Plot: # Generate figure (set its size (width, height) in inches) and axes plt.figure(figsize=(7, 6.5)) ax = plt.gca() # Plot slices of data U.isel(time=0).sel(lon=82, method='nearest').plot(x="lat", marker='', color='#C0C2EA', linewidth=1.1) U.isel(time=0).sel(lon=-69, method='nearest').plot(x="lat", marker='', color='#E28D90', linewidth=1.1, linestyle='--', dashes=[6.5, 3.7]) # Use geocat.viz.util convenience function to add minor and major tick lines gvutil.add_major_minor_ticks(ax, x_minor_per_major=3, y_minor_per_major=5, labelsize=16) # Use geocat.viz.util convenience function to set axes parameters without calling several matplotlib functions # Set axes limits, tick values, and tick labels to show latitude & longitude (i.e. North (N) - South (S)) gvutil.set_axes_limits_and_ticks(ax, xlim=(-90,90), ylim=(-20,50), xticks=np.linspace(-90, 90, 7), yticks=np.linspace(-20, 50, 8), xticklabels=['90S', '60S', '30S', '0', '30N', '60N', '90N']) # Use geocat.viz.util convenience function to set titles and labels without calling several matplotlib functions gvutil.set_titles_and_labels(ax, maintitle="Two Curve XY Plot", xlabel="", ylabel="Zonal Wind") # Show the plot plt.tight_layout() plt.show()
widths=[w, w, w], showfliers=False) # Set whiskers style to dashed plt.setp(boxplots['whiskers'], linestyle='--') # Set median line to black plt.setp(boxplots['medians'], color='black') # Remove axis lines on top and right sides ax.spines['right'].set_visible(False) ax.spines['top'].set_visible(False) # Use geocat.viz.util convenience function to set axes tick values gvutil.set_axes_limits_and_ticks(ax, ylim=(-6.0, 9.0), yticks=[-3.0, 0.0, 3.0, 6.0]) # Use geocat.viz.util convenience function to add minor and major tick lines gvutil.add_major_minor_ticks(ax, y_minor_per_major=3, x_minor_per_major=1, labelsize=14) # Use geocat.viz.util convenience function to add title to the plot axis. gvutil.set_titles_and_labels(ax, maintitle='Default Box Plot') # Make both major and minor ticks point inwards towards the plot ax.tick_params(direction="in", which='both') # Set ticks only at left and bottom sides of plot
# Plot original data # Note that the s parameter sets the size of the markers in pts plt.scatter(x, y, color='red', s=4) # Plot regression plt.plot(x_regress, y_regress, color='black', linewidth=0.5) # specify X and Y axis limits plt.xlim([6000, 9000]) plt.ylim([266, 274]) # Use geocat.viz utility functions to add a main title gvutil.set_titles_and_labels(ax=ax, maintitle="Regression 1") # Use geocat.viz.util convenience function to add minor and major tick lines gvutil.add_major_minor_ticks(ax, x_minor_per_major=5, y_minor_per_major=4, labelsize=12) # Use geocat.viz.util convenience function to set axes parameters gvutil.set_axes_limits_and_ticks(ax, xlim=(6000, 9000), xticks=np.arange(6000, 9001, 500), ylim=(266, 274), yticks=np.arange(266, 275, 2)) # Show plot plt.tight_layout() plt.show()
# Use the geocat.viz function to set the main title of the plot gvutil.set_titles_and_labels(axin, maintitle='Meteogram for LGSA, 28/12Z', maintitlefontsize=18, ylabel='Pressure (mb)', labelfontsize=12) # Add a pad between the y axis label and the axis spine axin.yaxis.labelpad = 5 # Use the geocat.viz function to set axes limits and ticks gvutil.set_axes_limits_and_ticks(axin, xlim=[taus[0], taus[-1]], ylim=[levels[0], levels[-1]], xticks=np.array(taus), yticks=np.linspace(1000, 400, 8), xticklabels=xticklabels, yticklabels=yticklabels) # Make axis invisible axin.patch.set_alpha(0.0) # Make ticks point inwards axin.tick_params(axis="x", direction="in", length=8) axin.tick_params(axis="y", direction="in", length=8, labelsize=9) # Rotate the labels on the x axis so they are vertical for tick in axin.get_xticklabels(): tick.set_rotation(90)
vmax=32, cmap=newcmp, add_colorbar=False) # Add colorbar cbar = plt.colorbar(heatmap, ticks=np.arange(0, 32, 2)) cbar.ax.set_yticklabels([str(i) for i in np.arange(0, 32, 2)]) # Adjust tick label size ax.tick_params(labelsize=12) # Use geocat.viz.util convenience function to set axes parameters without calling several matplotlib functions # Set axes limits, and tick values gvutil.set_axes_limits_and_ticks(ax, xlim=(30, 120), ylim=(-60, 30), xticks=np.linspace(-180, 180, 25), yticks=np.linspace(-90, 90, 13)) # Use geocat.viz.util convenience function to make plots look like NCL plots by using latitude, longitude tick labels gvutil.add_lat_lon_ticklabels(ax) # Use geocat.viz.util convenience function to set titles and labels without calling several matplotlib functions gvutil.set_titles_and_labels(ax, maintitle="15-degree major but no minor ticks", maintitlefontsize=16, lefttitle="Potential Temperature", lefttitlefontsize=14, righttitle="Celsius", righttitlefontsize=14, xlabel="",
plt.tick_params(which='major', length=10.0, width=0.5) plt.tick_params(which='minor', length=5.0, width=0.25) # Set the minor tick spacing for X and Y axes. ax1.xaxis.set_minor_locator(MultipleLocator(1.25)) ax1.yaxis.set_minor_locator(MultipleLocator(0.5)) # Add a descriptive string to the top left corner of the plot. ax1.text(0.01, 1.1, spacingString, transform=ax1.transAxes, fontWeight='bold') # Plot data and set the X axis limits. plt.plot(x_data, y_data, color='black', linewidth=0.5) # Usa geocat.viz.util convenience function to set axes parameters without calling several matplotlib functions # Set axes limits gvutil.set_axes_limits_and_ticks(ax1, xlim=(1949, 2006), ylim=(-4.2, 4.2)) # Make a subplot with major ticks that are set to explicit values and minor ticks that are multiples of 1. # Set the current plot context to the bottom subplot. ax2 = plt.subplot(2, 1, 2) # Format the tick labels. # For the minor ticks, use no labels; defaults to NullFormatter. ax2.xaxis.set_major_formatter(FormatStrFormatter('%d')) ax2.yaxis.set_major_formatter(FormatStrFormatter('%.1f')) # Draw ticks on all sides of the plot. plt.tick_params(which='both', top=True, right=True) # Increase the length of the tick marks.
V = gvutil.xr_add_cyclic_longitudes(V, "lon") ############################################################################### # Plot: # Generate figure (set its size (width, height) in inches) fig = plt.figure(figsize=(10, 6)) # Generate axes using Cartopy and draw coastlines ax = plt.axes(projection=ccrs.PlateCarree()) ax.coastlines(linewidths=0.5, alpha=0.6) # Use geocat.viz.util convenience function to set axes limits & tick values gvutil.set_axes_limits_and_ticks(ax, xlim=(-180, 180), ylim=(-90, 90), xticks=np.linspace(-180, 180, 13), yticks=np.linspace(-90, 90, 7)) # Use geocat.viz.util convenience function to add minor and major tick lines gvutil.add_major_minor_ticks(ax, labelsize=10) # Use geocat.viz.util convenience function to make latitude, longitude tick labels gvutil.add_lat_lon_ticklabels(ax) # Remove degree symbol from tick labels ax.yaxis.set_major_formatter(LatitudeFormatter(degree_symbol='')) ax.xaxis.set_major_formatter(LongitudeFormatter(degree_symbol='')) # Use geocat.viz.util convenience function to add titles gvutil.set_titles_and_labels(ax, lefttitle=V.long_name,
linewidths=0.5, colors='k', add_colorbar=False, transform=projection, extend='neither', add_labels=False) # Add horizontal colorbar cbar = plt.colorbar(p, orientation='horizontal', shrink=0.5) cbar.ax.tick_params(labelsize=16) cbar.set_ticks(np.linspace(0, 9, 10)) # Use geocat.viz.util convenience function to set axes limits & tick values without calling several matplotlib functions gvutil.set_axes_limits_and_ticks(ax, xlim=(0, 49), ylim=(0, 29), xticks=np.linspace(0, 40, 5), yticks=np.linspace(0, 25, 6)) # Use geocat.viz.util convenience function to add minor and major tick lines gvutil.add_major_minor_ticks(ax, x_minor_per_major=5, y_minor_per_major=5, labelsize=16) # Use geocat.viz.util convenience function to add titles to left and right of the plot axis. gvutil.set_titles_and_labels(ax, lefttitle="Cone amplitude", lefttitlefontsize=18, righttitle="ndim", righttitlefontsize=18,
################################################################################ # Plot: # Generate figure (set its size (width, height) in inches) and axes (with two different y-axes) fig, ax1 = plt.subplots(figsize=(7, 6.5)) # Plot data ax1.plot(ds.time, ds.T, color="blue", linestyle="-", linewidth=0.9) # Usa geocat.viz.util convenience function to add minor and major tick lines gvutil.add_major_minor_ticks(ax1, x_minor_per_major=5, labelsize=14) # Usa geocat.viz.util convenience function to set axes parameters without calling several matplotlib functions # Set axes limits, and tick values gvutil.set_axes_limits_and_ticks(ax1, xlim=(1970, 1973), ylim=(0.0, 16.0), yticks=np.arange(0, 17, 3)) # Usa geocat.viz.util convenience function to set titles and labels without calling several matplotlib functions gvutil.set_titles_and_labels(ax1, maintitle="Curves Offset", xlabel=ds.time.long_name, ylabel=f"{ds.T.long_name} [solid]") # Create second y-axis ax2 = ax1.twinx() # Use geocat.viz.util convenience function to add minor and major tick lines gvutil.add_major_minor_ticks(ax2, x_minor_per_major=5, labelsize=14) # Line-plot data
# `ncol` being equal to the number of labels makes it appear horizontal legend = ax.legend(bbox_to_anchor=(-0.075, -0.2), ncol=numBins, loc='lower left', columnspacing=0.5, frameon=False) for txt in legend.get_texts(): txt.set_ha("center") # horizontal alignment of text item txt.set_va("center") # vertical alignment of text item # Move label text so it is centered under the marker txt.set_x(-25) # x-position txt.set_y(-20) # y-position # Use geocat.viz.util convenience function to set axes parameters gvutil.set_axes_limits_and_ticks(ax, xlim=(0, 300), ylim=(0, 21), xticks=range(0, 301, 50), yticks=range(0, 22, 3)) # Use geocat.viz.util convenience function to add minor and major tick lines gvutil.add_major_minor_ticks(ax, x_minor_per_major=5, y_minor_per_major=3, labelsize=14) # Use geocat.viz.util convenience function to set titles and labels gvutil.set_titles_and_labels(ax, maintitle="Scatter plot with grouped markers") plt.show()
gavav_avg, color='red', label='Anthropogenic + Natural', zorder=2) ax.legend(loc='upper left', frameon=False, fontsize=18) # Use geocat.viz.util convenience function to add minor and major tick lines gvutil.add_major_minor_ticks(ax, x_minor_per_major=4, y_minor_per_major=3, labelsize=20) # Use geocat.viz.util convenience function to set axes limits & tick values without calling several matplotlib functions gvutil.set_axes_limits_and_ticks(ax, xlim=(1890, 2000), ylim=(-0.4, 1), xticks=np.arange(1900, 2001, step=20), yticks=np.arange(-0.3, 1, step=0.3)) # Set three titles on top of each other using axes title and texts ax.set_title('Parallel Climate Model Ensembles', fontsize=24, pad=60.0) ax.text(0.5, 1.125, 'Global Temperature Anomalies', fontsize=18, ha='center', va='center', transform=ax.transAxes) ax.text(0.5, 1.06, 'from 1890-1919 average',