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
) thewidth
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, ax=ax) # Pass different values for coloring (here, x-values). fig, ax = plt.subplots() colored_bars(x, y, c=x) plt.show()