data = (state.rand(40, 40) - 0.5).cumsum(axis=0).cumsum(axis=1) # Generate figure fig, axs = plot.subplots(ncols=2, nrows=2, axwidth=1.7, span=False) axs.format( xlabel='x axis', ylabel='y axis', suptitle='Modifying diverging colormaps', ) # Cutting out central colors levels = plot.arange(-10, 10, 2) for i, (ax, cut) in enumerate(zip(axs, (None, None, 0.2, -0.1))): levels = plot.arange(-10, 10, 2) if i == 1 or i == 3: levels = plot.edges(levels) if i == 0: title = 'Even number of levels' elif i == 1: title = 'Odd number of levels' else: title = 'Sharper cutoff' if cut > 0 else 'Expanded center' title = f'{title}\ncut = ${cut}$' ax.format(title=title) m = ax.contourf( data, cmap='Div', cmap_kw={'cut': cut}, extend='both', levels=levels, colorbar='b',
# limits if they were previously fixed by `~matplotlib.axes.Axes.set_xlim` or # `~matplotlib.axes.Axes.set_ylim` (or, equivalently, by passing `xlim` or # `ylim` to `proplot.axes.CartesianAxes.format`). This can be useful if you # wish to restrict the view along the *x* or *y* axis within a large dataset. # To disable this feature, pass ``inbounds=False`` to the plotting command or # set :rcraw:`cmap.inbounds` to ``False`` (see also the :rcraw:`axes.inbounds` # setting and the :ref:`user guide <ug_1dstd>`). # %% import proplot as pplt import numpy as np # Sample data state = np.random.RandomState(51423) x = y = np.array([-10, -5, 0, 5, 10]) xedges = pplt.edges(x) yedges = pplt.edges(y) data = state.rand(y.size, x.size) # "center" coordinates lim = (np.min(xedges), np.max(xedges)) with pplt.rc.context({'cmap': 'Grays', 'cmap.levels': 21}): # Figure fig = pplt.figure(refwidth=2.3, share=False) axs = fig.subplots(ncols=2, nrows=2) axs.format( xlabel='xlabel', ylabel='ylabel', xlim=lim, ylim=lim, xlocator=5, ylocator=5,
title, cmap_kw = f'left={coord}', {'left': coord} else: title, cmap_kw = f'right={coord}', {'right': coord} ax.pcolormesh(data, cmap=cmap, cmap_kw=cmap_kw, colorbar='b', colorbar_kw={'locator': 'null'}) ax.format(xlabel='x axis', ylabel='y axis', title=title) # Cutting central colors levels = plot.arange(-10, 10, 2) for i, (ax, cut) in enumerate(zip(axs[3:], (None, None, 0.1, 0.2))): if i == 0: title = 'With central level' levels = plot.edges(plot.arange(-10, 10, 2)) else: title = 'Without central level' levels = plot.arange(-10, 10, 2) if cut is not None: title = f'cut = {cut}' m = ax.contourf( data, cmap='Div', cmap_kw={'cut': cut}, extend='both', levels=levels, ) ax.format(xlabel='x axis', ylabel='y axis', title=title,
# positional arguments across all 2D plotting methods. Among other things, # it guesses coordinate *edges* for `~matplotlib.axes.Axes.pcolor` and # `~matplotlib.axes.Axes.pcolormesh` plots when you supply coordinate # *centers*, and calculates coordinate *centers* for # `~matplotlib.axes.Axes.contourf` and `~matplotlib.axes.Axes.contour` plots # when you supply coordinate *edges*. Notice the locations of the rectangle # edges in the ``pcolor`` plots shown below. # %% import proplot as plot import numpy as np # Figure and sample data state = np.random.RandomState(51423) x = y = np.array([-10, -5, 0, 5, 10]) xedges = plot.edges(x) yedges = plot.edges(y) data = state.rand(y.size, x.size) # "center" coordinates lim = (np.min(xedges), np.max(xedges)) with plot.rc.context({'image.cmap': 'Grays', 'image.levels': 21}): fig, axs = plot.subplots(ncols=2, nrows=2, share=False) axs.format( xlabel='xlabel', ylabel='ylabel', xlim=lim, ylim=lim, xlocator=5, ylocator=5, suptitle='Standardized input demonstration' ) axs[0].format(title='Supplying coordinate centers') axs[1].format(title='Supplying coordinate edges') # Plot using both centers and edges as coordinates axs[0].pcolormesh(x, y, data)