colored_bars

typhon.plots.colored_bars(x, y, c=None, cmap=None, vmin=None, vmax=None, ax=None, **kwargs)[source]

Plot a colorized series of bars.

Note

If the x-values are floats (smaller than 1) the width should be adjusted to prevent bars from overlapping.

Parameters
  • x (ndarray) – Abscissa values.

  • y (ndarray) – Ordinate values.

  • c (ndarray) – (Optional) values for color scaling.

  • cmap (str or matplotlib.colors.Colormap) – The colormap used to map normalized data values to RGBA colors.

  • vmin (float) – Set lower color limit.

  • vmax (float) – Set upper color limit.

  • ax (AxesSubplot) – Axes to plot into.

  • **kwargs – Additional keyword arguments are passed to matplotlib.pyplot.bar().

Returns

Mappable, Artists corresponding to each bar.

Return type

matplotlib.cm.ScalarMappable, matplotlib.container.BarContainer

Examples:

import numpy as np
import matplotlib.pyplot as plt

from typhon.plots import colored_bars


N = 50
x = np.arange(N)
y = np.sin(np.linspace(0, 3 * np.pi, N)) + 0.5 * np.random.randn(N)

# Basic series with bars colored according to y-value.
fig, ax = plt.subplots()
colored_bars(x, y, cmap='seismic')

# Add a colorbar to the figure.
fig, ax = plt.subplots()
sm, bars = colored_bars(x, y, cmap='seismic')
cb = fig.colorbar(sm)

# Pass different values for coloring (here, x-values).
fig, ax = plt.subplots()
colored_bars(x, y, c=x)

plt.show()

(Source code)

../_images/typhon-plots-colored_bars-1_00.png

Fig. 3 (png, hires.png, pdf)

../_images/typhon-plots-colored_bars-1_01.png

Fig. 4 (png, hires.png, pdf)

../_images/typhon-plots-colored_bars-1_02.png

Fig. 5 (png, hires.png, pdf)