🌐 AI搜索 & 代理 主页
Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions tutorials/colors/colorbar_only.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

:class:`~matplotlib.colorbar.ColorbarBase` derives from
:mod:`~matplotlib.cm.ScalarMappable` and puts a colorbar in a specified axes,
so it has everything needed for a standalone colorbar. It can be used as is to
make a colorbar for a given colormap and does not need a mappable object like
so it has everything needed for a standalone colorbar. It can be used as-is to
make a colorbar for a given colormap; it does not need a mappable object like
an image. In this tutorial we will explore what can be done with standalone
colorbar.

Expand All @@ -22,14 +22,15 @@
will be used. Then create the colorbar by calling
:class:`~matplotlib.colorbar.ColorbarBase` and specify axis, colormap, norm
and orientation as parameters. Here we create a basic continuous colorbar
with ticks and labels. More information on colorbar api can be found
`here <https://matplotlib.org/api/colorbar_api.html>`.
with ticks and labels. More information on the colorbar API can be found
`here <https://matplotlib.org/api/colorbar_api.html>`_.
"""

import matplotlib.pyplot as plt
import matplotlib as mpl

fig, ax = plt.subplots()
fig, ax = plt.subplots(figsize=(6, 1))
fig.subplots_adjust(bottom=0.5)

cmap = mpl.cm.cool
norm = mpl.colors.Normalize(vmin=5, vmax=10)
Expand Down Expand Up @@ -62,7 +63,8 @@
# *extend*, you must specify two extra boundaries. Finally spacing argument
# ensures that intervals are shown on colorbar proportionally.

fig, ax = plt.subplots()
fig, ax = plt.subplots(figsize=(6, 1))
fig.subplots_adjust(bottom=0.5)

cmap = mpl.colors.ListedColormap(['red', 'green', 'blue', 'cyan'])
cmap.set_over('0.25')
Expand All @@ -85,10 +87,11 @@
# --------------------------------------
#
# Here we illustrate the use of custom length colorbar extensions, used on a
# colorbar with discrete intervals. To make the length of each extension same
# as the length of the interior colors, use ``extendfrac='auto'``.
# colorbar with discrete intervals. To make the length of each extension the
# same as the length of the interior colors, use ``extendfrac='auto'``.

fig, ax = plt.subplots()
fig, ax = plt.subplots(figsize=(6, 1))
fig.subplots_adjust(bottom=0.5)

cmap = mpl.colors.ListedColormap(['royalblue', 'cyan',
'yellow', 'orange'])
Expand Down