4 examples of 'matplotlib colorbar title' in Python

Every line of 'matplotlib colorbar title' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
893def ax_colorbar(vmin, vmax, ax=None, label=None, ticks=None):
894 """Draw a color bar
895
896 Draws a color bar on an existing axes. The range of the colors is
897 defined by ``vmin`` and ``vmax``.
898
899 .. note::
900
901 Unlike the colorbar method from matplotlib, this method does not
902 automatically create a new axis for the colorbar. It will paint
903 in the currently active axis instead, overwriting any existing
904 plots in that axis. Make sure to create a new axis for the
905 colorbar.
906
907 Parameters
908 ----------
909 vmin, vmax : float
910 The minimum and maximum values for the colorbar.
911 ax : Axes, optional
912 The axes to draw the scalp plot on. If not provided, the
913 currently activated axes (i.e. ``gca()``) will be taken
914 label : string, optional
915 The label for the colorbar
916 ticks : list, optional
917 The tick positions
918
919 Returns
920 -------
921 ax : Axes
922 the axes on which the plot was drawn
923 """
924 if ax is None:
925 ax = plt.gca()
926 ColorbarBase(ax, norm=Normalize(vmin, vmax), label=label, ticks=ticks)
147def plot_topo_colorbar(vmin, vmax, label):
148 """Helper function to create colorbars for the topography plots."""
149
150 fig = plt.figure(figsize=(2, 3))
151 ax1 = fig.add_axes([0.9, 0.25, 0.15, 0.9])
152
153 cmap = cm.viridis
154 norm = colors.Normalize(vmin=vmin, vmax=vmax)
155
156 cb1 = colorbar.ColorbarBase(plt.gca(), cmap=cmap,
157 norm=norm, orientation='vertical')
109def colorbar(mappable):
110 ax = mappable.axes
111 fig = ax.figure
112 divider = make_axes_locatable(ax)
113 cax = divider.append_axes('right', size='5%', pad=0.05)
114 return fig.colorbar(mappable, cax=cax)
2220def _colorbar(off=0.0, colors=256, label_name='zlabel'):
2221 global _plt
2222 gr.savestate()
2223 viewport = _plt.kwargs['viewport']
2224 zmin, zmax = _plt.kwargs['zrange']
2225 gr.setwindow(0, 1, zmin, zmax)
2226 gr.setviewport(viewport[1] + 0.02 + off, viewport[1] + 0.05 + off,
2227 viewport[2], viewport[3])
2228
2229 if colors == 1:
2230 data = [1000]
2231 else:
2232 data = [1000 + int(255 * i / (colors - 1)) for i in range(colors)]
2233
2234 gr.setlinecolorind(1)
2235 gr.setscale(0)
2236 if _plt.kwargs['scale'] & gr.OPTION_FLIP_Z:
2237 gr.cellarray(0, 1, zmin, zmax, 1, colors, data)
2238 else:
2239 gr.cellarray(0, 1, zmax, zmin, 1, colors, data)
2240 diag = ((viewport[1] - viewport[0])**2 + (viewport[3] - viewport[2])**2)**0.5
2241 charheight = max(0.016 * diag, 0.012)
2242 gr.setcharheight(charheight)
2243 if _plt.kwargs['scale'] & gr.OPTION_Z_LOG:
2244 if _plt.kwargs['scale'] & gr.OPTION_FLIP_Z:
2245 gr.setscale(gr.OPTION_Y_LOG | gr.OPTION_FLIP_Y)
2246 else:
2247 gr.setscale(gr.OPTION_Y_LOG)
2248 gr.axes(0, 2, 1, zmin, 0, 1, 0.005)
2249 else:
2250 if _plt.kwargs['scale'] & gr.OPTION_FLIP_Z:
2251 gr.setscale(gr.OPTION_FLIP_Y)
2252 else:
2253 gr.setscale(0)
2254 ztick = 0.5 * gr.tick(zmin, zmax)
2255 gr.axes(0, ztick, 1, zmin, 0, 1, 0.005)
2256 label = _plt.kwargs.get(label_name, None)
2257 if label:
2258 diag = ((viewport[1] - viewport[0])**2 + (viewport[3] - viewport[2])**2)**0.5
2259 charheight = max(0.018 * diag, 0.012)
2260 gr.setcharheight(charheight)
2261 gr.settextalign(gr.TEXT_HALIGN_CENTER, gr.TEXT_VALIGN_BASE)
2262 gr.textext(viewport[1] + 0.035 + off, viewport[3] + 0.01, label)
2263 gr.restorestate()

Related snippets