コード例 #1
0
def main():
    fig, axes = setup_axes()
    plot(axes, *load_data())
    example_utils.title(fig,
                        '"ax.imshow(data, ...)": Colormapped or RGB arrays')
    fig.savefig('imshow_example.png', facecolor='none')
    plt.show()
コード例 #2
0
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()
コード例 #3
0
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()
コード例 #4
0
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()
コード例 #5
0
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()
コード例 #6
0
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
axes[2].streamplot(xi, yi, dx, dy, color=z, density=1.5, linewidth=lw,
                   cmap='gist_earth')
example_utils.label(axes[2], 'streamplot(x, y, dx, dy)')

example_utils.title(fig, '"arrow/quiver/streamplot": Vector fields', y=0.96)
fig.savefig('vector_example.png', facecolor='none')

plt.show()
コード例 #7
0
ファイル: pcolor_example.py プロジェクト: mischaaf/lectures
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)
example_utils.label(axes[2], 'pcolormesh(x,y,z)')

example_utils.title(fig, 'pcolor/pcolormesh: Colormapped 2D arrays')
fig.savefig('pcolor_example.png', facecolor='none')

plt.show()
コード例 #8
0
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)
example_utils.label(axes[2], 'pcolormesh(x,y,z)')

example_utils.title(fig, 'pcolor/pcolormesh: Colormapped 2D arrays')
fig.savefig('pcolor_example.png', facecolor='none')

plt.show()
コード例 #9
0
"""
Illustrates the basics of using "scatter".
"""
import numpy as np
import matplotlib.pyplot as plt

import example_utils

# Generate some random data...
np.random.seed(1874)
x, y, z = np.random.normal(0, 1, (3, 100))
t = np.arctan2(y, x)
size = 50 * np.cos(2 * t)**2 + 10

fig, axes = example_utils.setup_axes()

axes[0].scatter(x, y, marker='o', facecolor='white', s=80)
example_utils.label(axes[0], 'scatter(x, y)')

axes[1].scatter(x, y, s=size, marker='s', color='darkblue')
example_utils.label(axes[1], 'scatter(x, y, s)')

axes[2].scatter(x, y, c=z, s=size, cmap='gist_ncar')
example_utils.label(axes[2], 'scatter(x, y, s, c)')

example_utils.title(fig, '"ax.scatter(...)": Colored/scaled markers', y=0.95)
fig.savefig('scatter_example.png', facecolor='none')

plt.show()
コード例 #10
0
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
axes[2].streamplot(xi, yi, dx, dy, color=z, density=1.5, linewidth=lw,
                   cmap='gist_earth')
example_utils.label(axes[2], 'streamplot(x, y, dx, dy)')

example_utils.title(fig, '"arrow/quiver/streamplot": Vector fields', y=0.96)
fig.savefig('vector_example.png', facecolor='none')

plt.show()
コード例 #11
0
import numpy as np
import matplotlib.pyplot as plt

import example_utils

x = np.linspace(0, 10, 100)

fig, axes = example_utils.setup_axes()
for ax in axes:
    ax.margins(y=0.10)

# Default plotting, colors will be determined by the axes' color_cycle
for i in range(1, 6):
    axes[0].plot(x, i * x)

# Demonstrating different linestyles
for i, ls in enumerate(['-', '--', ':', '-.']):
    axes[1].plot(x, np.cos(x) + i, linestyle=ls)

# Using linestyles and markers
for i, (ls, mk) in enumerate(zip(['', '-', ':'], ['o', '^', 's'])):
    axes[2].plot(x, np.cos(x) + i * x, linestyle=ls, marker=mk, markevery=10)

example_utils.title(fig, '"ax.plot(x, y, ...)": Lines and/or markers', y=0.95)
fig.savefig('plot_example.png', facecolor='none')

plt.show()
コード例 #12
0
ファイル: contour_example.py プロジェクト: mischaaf/lectures
import matplotlib
matplotlib.use('nbAgg')

import matplotlib.pyplot as plt
import numpy as np
from matplotlib.cbook import get_sample_data

import example_utils

z = np.load(get_sample_data('axes_grid/bivariate_normal.npy'))

fig, axes = example_utils.setup_axes()

axes[0].contour(z, cmap='gist_earth')
example_utils.label(axes[0], 'contour')

axes[1].contourf(z, cmap='gist_earth')
example_utils.label(axes[1], 'contourf')

axes[2].contourf(z, cmap='gist_earth')
cont = axes[2].contour(z, colors='black')
axes[2].clabel(cont, fontsize=6)
example_utils.label(axes[2], 'contourf + contour\n + clabel')

example_utils.title(fig, '"contour, contourf, clabel": Contour/label 2D data',
                    y=0.96)
fig.savefig('contour_example.png', facecolor='none')

plt.show()
コード例 #13
0
"""
Illustrates the basics of using "scatter".
"""
import numpy as np
import matplotlib.pyplot as plt

import example_utils

# Generate some random data...
np.random.seed(1874)
x, y, z = np.random.normal(0, 1, (3, 100))
t = np.arctan2(y, x)
size = 50 * np.cos(2 * t)**2 + 10

fig, axes = example_utils.setup_axes()

axes[0].scatter(x, y, marker='o', facecolor='white', s=80)
example_utils.label(axes[0], 'scatter(x, y)')

axes[1].scatter(x, y, s=size, marker='s', color='darkblue')
example_utils.label(axes[1], 'scatter(x, y, s)')

axes[2].scatter(x, y, c=z, s=size, cmap='gist_ncar')
example_utils.label(axes[2], 'scatter(x, y, s, c)')

example_utils.title(fig,'"ax.scatter(...)": Colored/scaled markers',
                    y=0.95)
fig.savefig('scatter_example.png', facecolor='none')

plt.show()
コード例 #14
0
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.cbook import get_sample_data

import example_utils

z = np.load(get_sample_data('axes_grid/bivariate_normal.npy'))

fig, axes = example_utils.setup_axes()

axes[0].contour(z, cmap='gist_earth')
example_utils.label(axes[0], 'contour')

axes[1].contourf(z, cmap='gist_earth')
example_utils.label(axes[1], 'contourf')

axes[2].contourf(z, cmap='gist_earth')
cont = axes[2].contour(z, colors='black')
axes[2].clabel(cont, fontsize=6)
example_utils.label(axes[2], 'contourf + contour\n + clabel')

example_utils.title(fig, '"contour, contourf, clabel": Contour/label 2D data',
                    y=0.96)
fig.savefig('contour_example.png', facecolor='none')

plt.show()
コード例 #15
0
def main():
    fig, axes = setup_axes()
    plot(axes, *load_data())
    example_utils.title(fig, '"ax.imshow(data, ...)": Colormapped or RGB arrays')
    fig.savefig('imshow_example.png', facecolor='none')
    plt.show()