You are reading documentation for the unreleased version of Matplotlib. Try searching for the released version of this page instead?
Version 2.1.1.post1120+g407a460
Fork me on GitHub

Related Topics

This Page

Create 2D bar graphs in different planesΒΆ

Demonstrates making a 3D plot which has 2D bar graphs projected onto planes y=0, y=1, etc.

from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np

# Fixing random state for reproducibility

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

colors = ['r', 'g', 'b', 'y']
yticks = [3, 2, 1, 0]
for c, k in zip(colors, yticks):
    # Generate the random data for the y=k 'layer'.
    xs = np.arange(20)
    ys = np.random.rand(20)

    # You can provide either a single color or an array with the same length as
    # xs and ys. To demonstrate this, we color the first bar of each set cyan.
    cs = [c] * len(xs)
    cs[0] = 'c'

    # Plot the bar graph given by xs and ys on the plane y=k with 80% opacity., ys, zs=k, zdir='y', color=cs, alpha=0.8)


# On the y axis let's only label the discrete values that we have data for.

Gallery generated by Sphinx-Gallery