|
229 | 229 | "ProPlot allows you to create modified versions of *existing* colormaps using the `~proplot.styletools.Colormap` constructor and the new `~proplot.styletools.LinearSegmentedColormap` and `~proplot.styletools.ListedColormap` classes, which are used to replace the native matplotlib colormap classes. They can be modified in the following ways:\n",
|
230 | 230 | "\n",
|
231 | 231 | "* To remove colors from the left or right ends of a colormap, pass `left` or `right` to `~proplot.styletools.Colormap`. This calls the `~proplot.styletools.LinearSegmentedColormap.truncated` method, and can be useful when you want to use colormaps as :ref:`Color cycles` and need to remove the \"white\" part so that your lines stand out against the background.\n",
|
232 |
| - "* To remove central colors from a diverging colormap, pass `cut` to `~proplot.styletools.Colormap`. This calls the `~proplot.styletools.LinearSegmentedColormap.punched` method, and can be useful when you want a sharper cutoff between negative and positive values.\n", |
| 232 | + "* To remove central colors from a diverging colormap, pass `cut` to `~proplot.styletools.Colormap`. This calls the `~proplot.styletools.LinearSegmentedColormap.punched` method, and can be used to create a sharper cutoff between negative and positive values. This should generally be used *without* a central level.\n", |
233 | 233 | "* To rotate a cyclic colormap, pass `shift` to `~proplot.styletools.Colormap`. This calls the `~proplot.styletools.LinearSegmentedColormap.shifted` method. ProPlot ensures the colors at the ends of \"shifted\" colormaps are *distinct* so that levels never blur together.\n",
|
234 | 234 | "* To change the transparency of an entire colormap, pass `alpha` to `~proplot.styletools.Colormap`. This calls the `~proplot.styletools.LinearSegmentedColormap.set_alpha` method, and can be useful when *layering* filled contour or mesh elements.\n",
|
235 | 235 | "* To change the \"gamma\" of a `~proplot.styletools.PerceptuallyUniformColormap`, pass `gamma` to `~proplot.styletools.Colormap`. This calls the `~proplot.styletools.PerceptuallyUniformColormap.set_gamma` method, and controls how the luminance and saturation channels vary between colormap segments. ``gamma > 1`` emphasizes high luminance, low saturation colors, while ``gamma < 1`` emphasizes low luminance, high saturation colors."
|
|
243 | 243 | "source": [
|
244 | 244 | "import proplot as plot\n",
|
245 | 245 | "import numpy as np\n",
|
246 |
| - "f, axs = plot.subplots([[1, 1, 2, 2, 3, 3], [0, 4, 4, 5, 5, 0]], axwidth=1.7)\n", |
| 246 | + "f, axs = plot.subplots([[1, 1, 2, 2, 3, 3, 4, 4], [0, 5, 5, 6, 6, 7, 7, 0]],\n", |
| 247 | + " axwidth=1.7, share=0, span=False)\n", |
247 | 248 | "state = np.random.RandomState(51423)\n",
|
248 |
| - "data = state.rand(50, 50).cumsum(axis=0) - 50\n", |
| 249 | + "data = state.rand(40, 40).cumsum(axis=0) - 12\n", |
249 | 250 | "# Cutting central colors\n",
|
250 |
| - "for ax, cut in zip(axs[:3], (0, 0.1, 0.2)):\n", |
251 |
| - " m = ax.contourf(data, cmap='Div', cmap_kw={'cut': cut}, levels=13)\n", |
252 |
| - " ax.format(xlabel='xlabel', ylabel='ylabel', title=f'cut = {cut}',\n", |
253 |
| - " suptitle='Slicing diverging and sequential colormaps')\n", |
| 251 | + "levels = plot.arange(-10, 10, 2)\n", |
| 252 | + "for i, (ax, cut) in enumerate(zip(axs[:4], (None, None, 0.1, 0.2))):\n", |
| 253 | + " if i == 0:\n", |
| 254 | + " title = 'With central level'\n", |
| 255 | + " levels = plot.edges(plot.arange(-10, 10, 2))\n", |
| 256 | + " else:\n", |
| 257 | + " title = 'Without central level'\n", |
| 258 | + " levels = plot.arange(-10, 10, 2)\n", |
| 259 | + " if cut is not None:\n", |
| 260 | + " title = f'cut = {cut}'\n", |
| 261 | + " m = ax.contourf(data, cmap='Div', cmap_kw={'cut': cut},\n", |
| 262 | + " extend='both', levels=levels)\n", |
| 263 | + " ax.format(xlabel='xlabel', ylabel='ylabel', title=title,\n", |
| 264 | + " suptitle='Truncating diverging and sequential colormaps')\n", |
254 | 265 | " ax.colorbar(m, loc='b', locator='null')\n",
|
255 | 266 | "# Cutting left and right\n",
|
256 |
| - "for ax, cut in zip(axs[3:], (0.2, 0.8)):\n", |
257 |
| - " if cut < 0.5:\n", |
258 |
| - " title, cmap, cmap_kw = f'left={cut}', 'grays', {'left': cut}\n", |
| 267 | + "for ax, coord in zip(axs[4:], (None, 0.3, 0.7)):\n", |
| 268 | + " cmap = 'grays'\n", |
| 269 | + " if coord is None:\n", |
| 270 | + " title, cmap_kw = 'Original', {}\n", |
| 271 | + " elif coord < 0.5:\n", |
| 272 | + " title, cmap_kw = f'left={coord}', {'left': coord}\n", |
259 | 273 | " else:\n",
|
260 |
| - " title, cmap, cmap_kw = f'right={cut}', 'grays', {'right': cut}\n", |
| 274 | + " title, cmap_kw = f'right={coord}', {'right': coord}\n", |
261 | 275 | " ax.pcolormesh(data, cmap=cmap, cmap_kw=cmap_kw,\n",
|
262 |
| - " colorbar='b', colorbar_kw={'locator': 'null'})\n", |
| 276 | + " colorbar='b', colorbar_kw={'locator': 'null'})\n", |
263 | 277 | " ax.format(xlabel='xlabel', ylabel='ylabel', title=title)\n",
|
264 | 278 | "# Rotating cyclic\n",
|
265 | 279 | "f, axs = plot.subplots(ncols=3, axwidth=1.7)\n",
|
|
0 commit comments