def main(): fig, axes = example_utils.setup_axes() basic_bar(axes[0]) tornado(axes[1]) general(axes[2]) example_utils.title(fig, '"ax.bar(...)": Plot rectangles') fig.savefig('bar_example.png', facecolor='none') plt.show()
def main(): fig, axes = example_utils.setup_axes() fill_example(axes[0]) fill_between_example(axes[1]) stackplot_example(axes[2]) example_utils.title(fig, 'fill/fill_between/stackplot: Filled polygons', y=0.95) fig.savefig('fill_example.png', facecolor='none') plt.show()
def main(): colors = ['cyan', 'red', 'blue', 'green', 'purple'] dists = generate_data() fig, axes = example_utils.setup_axes() hist(axes[0], dists, colors) boxplot(axes[1], dists, colors) violinplot(axes[2], dists, colors) example_utils.title(fig, 'hist/boxplot/violinplot: Statistical plotting', y=0.9) fig.savefig('statistical_example.png', facecolor='none') plt.show()
import matplotlib.pyplot as plt import numpy as np import example_utils # Generate data n = 256 x = np.linspace(-3, 3, n) y = np.linspace(-3, 3, n) xi, yi = np.meshgrid(x, y) z = (1 - xi / 2 + xi**5 + yi**3) * np.exp(-xi**2 - yi**2) dy, dx = np.gradient(z) mag = np.hypot(dx, dy) fig, axes = example_utils.setup_axes() # Use ax.arrow to plot a single arrow on the axes. axes[0].arrow(0, 0, -0.5, 0.5, width=0.005, color='black') axes[0].axis([-1, 1, -1, 1]) example_utils.label(axes[0], 'arrow(x, y, dx, dy)') # Plot a regularly-sampled vector field with ax.quiver ds = np.s_[::16, ::16] # Downsample our array a bit... axes[1].quiver(xi[ds], yi[ds], dx[ds], dy[ds], z[ds], cmap='gist_earth', width=0.01, scale=0.25, pivot='middle') axes[1].axis('tight') example_utils.label(axes[1], 'quiver(x, y, dx, dy)') # Use ax.streamplot to show flowlines through our vector field # We'll get fancy and vary their width and color lw = 2 * (mag - mag.min()) / mag.ptp() + 0.2
import matplotlib.pyplot as plt import numpy as np from matplotlib.cbook import get_sample_data import example_utils # Set up our data... z = np.load(get_sample_data('axes_grid/bivariate_normal.npy')) ny, nx = z.shape y, x = np.mgrid[:ny, :nx] y = (y - y.mean()) * (x + 10)**2 mask = (z > -0.1) & (z < 0.1) z2 = np.ma.masked_where(mask, z) fig, axes = example_utils.setup_axes() # Either pcolor or pcolormesh would produce the same result here. # pcolormesh is faster, however. axes[0].pcolor(x, y, z, cmap='gist_earth') example_utils.label(axes[0], 'either') # The difference between the two will become clear as we turn on edges: # pcolor will completely avoid drawing masked cells... axes[1].pcolor(x, y, z2, cmap='gist_earth', edgecolor='black') example_utils.label(axes[1], 'pcolor(x,y,z)') # While pcolormesh will draw them as empty (but still present) cells. axes[2].pcolormesh(x, y, z2, cmap='gist_earth', edgecolor='black', lw=0.5, antialiased=True)