# Turning on inline plots -- just for use in ipython notebooks. %pylab inline import matplotlib.pyplot as plt import numpy as np t = np.arange(0.0, 5.0, 0.2) plt.plot(t, t, 'r', t, t**2, 'cyan', t, t**3, '0.7') plt.show() marker description ==================== =================================== "." point "," pixel "o" circle "v" triangle_down "^" triangle_up "<" triangle_left ">" triangle_right "1" tri_down "2" tri_up "3" tri_left "4" tri_right "8" octagon "s" square "p" pentagon "*" star "h" hexagon1 "H" hexagon2 "+" plus "x" x "D" diamond "d" thin_diamond "|" vertical line "_" horizontal line 0 tickleft 1 tickright 2 tickup 3 tickdown 4 caretleft 5 caretright 6 caretup 7 caretdown "None" nothing None nothing " " nothing "" nothing "$...$" render the string using mathtext. ==================== ====================================== t = np.arange(0.0, 5.0, 0.2) plt.plot(t, t, 'D', t, t**2, '3', t, t**3, 'x') plt.show() linestyle description ================ ================= '-' solid '--' dashed '-.' dashdot ':' dotted 'None' draw nothing ' ' draw nothing '' draw nothing ================ ================= t = np.arange(0.0, 5.0, 0.2) plt.plot(t, t, '-', t, t**2, '--', t, t**3, '-.', t, -t, ':') plt.show() fig, ax = plt.subplots(1, 1) ax.bar([1, 2, 3, 4], [10, 20, 15, 13], ls='dashed', ec='r', lw=5) plt.show() t = np.arange(0., 5., 0.2) # red dashes, blue squares and green triangles plt.plot(t, t, 'r--', t, t**2, 'bs', t, t**3, 'g^') plt.show() | Property | Value Type | |------------------------|-------------------------------------------------| |alpha | float | |color or c | any matplotlib color | |dash_capstyle | ['butt' | 'round' | 'projecting'] | |dash_joinstyle | ['miter' | 'round' | 'bevel'] | |dashes | sequence of on/off ink in points | |drawstyle | [ ‘default’ | ‘steps’ | ‘steps-pre’ | | | | ‘steps-mid’ | ‘steps-post’ ] | |linestyle or ls | [ '-' | '--' | '-.' | ':' | 'None' | ' ' | '' ] | | | and any drawstyle in combination with a | | | linestyle, e.g. 'steps--'. | |linewidth or lw | float value in points | |marker | [ 7 | 4 | 5 | 6 | 'o' | 'D' | 'h' | 'H' | '_' | | | | '' | 'None' | ' ' | None | '8' | 'p' | ',' | | | | '+' | '.' | 's' | '*' | 'd' | 3 | 0 | 1 | 2 | | | | '1' | '3' | '4' | '2' | 'v' | '<' | '>' | | | | '^' | '|' | 'x' | '$...$' | tuple | Nx2 array ]| |markeredgecolor or mec | any matplotlib color | |markeredgewidth or mew | float value in points | |markerfacecolor or mfc | any matplotlib color | |markersize or ms | float | |solid_capstyle | ['butt' | 'round' | 'projecting'] | |solid_joinstyle | ['miter' | 'round' | 'bevel'] | |visible | [True | False] | |zorder | any number | ---------------------------------------------------------------------------- t = np.arange(0.0, 5.0, 0.1) a = np.exp(-t) * np.cos(2*np.pi*t) plt.plot(t, a, ) plt.show() %load http://matplotlib.org/1.3.0/mpl_examples/color/colormaps_reference.py # For those with v1.2 or higher #%load http://matplotlib.org/examples/pylab_examples/show_colormaps.html # For those with pre-v1.2 """ Reference for colormaps included with Matplotlib. This reference example shows all colormaps included with Matplotlib. Note that any colormap listed here can be reversed by appending "_r" (e.g., "pink_r"). These colormaps are divided into the following categories: Sequential: These colormaps are approximately monochromatic colormaps varying smoothly between two color tones---usually from low saturation (e.g. white) to high saturation (e.g. a bright blue). Sequential colormaps are ideal for representing most scientific data since they show a clear progression from low-to-high values. Diverging: These colormaps have a median value (usually light in color) and vary smoothly to two different color tones at high and low values. Diverging colormaps are ideal when your data has a median value that is significant (e.g. 0, such that positive and negative values are represented by different colors of the colormap). Qualitative: These colormaps vary rapidly in color. Qualitative colormaps are useful for choosing a set of discrete colors. For example:: color_list = plt.cm.Set3(np.linspace(0, 1, 12)) gives a list of RGB colors that are good for plotting a series of lines on a dark background. Miscellaneous: Colormaps that don't fit into the categories above. """ import numpy as np import matplotlib.pyplot as plt cmaps = [('Sequential', ['binary', 'Blues', 'BuGn', 'BuPu', 'gist_yarg', 'GnBu', 'Greens', 'Greys', 'Oranges', 'OrRd', 'PuBu', 'PuBuGn', 'PuRd', 'Purples', 'RdPu', 'Reds', 'YlGn', 'YlGnBu', 'YlOrBr', 'YlOrRd']), ('Sequential (2)', ['afmhot', 'autumn', 'bone', 'cool', 'copper', 'gist_gray', 'gist_heat', 'gray', 'hot', 'pink', 'spring', 'summer', 'winter']), ('Diverging', ['BrBG', 'bwr', 'coolwarm', 'PiYG', 'PRGn', 'PuOr', 'RdBu', 'RdGy', 'RdYlBu', 'RdYlGn', 'seismic']), ('Qualitative', ['Accent', 'Dark2', 'hsv', 'Paired', 'Pastel1', 'Pastel2', 'Set1', 'Set2', 'Set3', 'spectral']), ('Miscellaneous', ['gist_earth', 'gist_ncar', 'gist_rainbow', 'gist_stern', 'jet', 'brg', 'CMRmap', 'cubehelix', 'gnuplot', 'gnuplot2', 'ocean', 'rainbow', 'terrain', 'flag', 'prism'])] nrows = max(len(cmap_list) for cmap_category, cmap_list in cmaps) gradient = np.linspace(0, 1, 256) gradient = np.vstack((gradient, gradient)) def plot_color_gradients(cmap_category, cmap_list): fig, axes = plt.subplots(nrows=nrows) fig.subplots_adjust(top=0.95, bottom=0.01, left=0.2, right=0.99) axes[0].set_title(cmap_category + ' colormaps', fontsize=14) for ax, name in zip(axes, cmap_list): ax.imshow(gradient, aspect='auto', cmap=plt.get_cmap(name)) pos = list(ax.get_position().bounds) x_text = pos[0] - 0.01 y_text = pos[1] + pos[3]/2. fig.text(x_text, y_text, name, va='center', ha='right', fontsize=10) # Turn off *all* ticks & spines, not just the ones with colormaps. for ax in axes: ax.set_axis_off() for cmap_category, cmap_list in cmaps: plot_color_gradients(cmap_category, cmap_list) plt.show() fig, (ax1, ax2) = plt.subplots(1, 2) z = np.random.random((10, 10)) ax1.imshow(z, interpolation='none', cmap='gray') ax2.imshow(z, interpolation='none', cmap='coolwarm') plt.show() plt.scatter([1, 2, 3, 4], [4, 3, 2, 1]) plt.title(r'$\sigma_i=15$', fontsize=20) plt.show() t = np.arange(0.0, 5.0, 0.01) s = np.cos(2*np.pi*t) line, = plt.plot(t, s, lw=2) plt.annotate('local max', xy=(2, 1), xytext=(3, 1.5), arrowprops=dict(facecolor='black', shrink=0.05)) plt.ylim(-2,2) plt.show() import matplotlib.patches as mpatches import matplotlib.pyplot as plt styles = mpatches.ArrowStyle.get_styles() ncol=2 nrow = (len(styles)+1) // ncol figheight = (nrow+0.5) fig1 = plt.figure(1, (4.0*ncol/0.85, figheight/0.85)) fontsize = 0.4 * 70 ax = fig1.add_axes([0, 0, 1, 1], frameon=False, aspect=1.) ax.set_xlim(0, 4*ncol) ax.set_ylim(0, figheight) def to_texstring(s): s = s.replace("<", r"$<$") s = s.replace(">", r"$>$") s = s.replace("|", r"$|$") return s for i, (stylename, styleclass) in enumerate(sorted(styles.items())): x = 3.2 + (i//nrow)*4 y = (figheight - 0.7 - i%nrow) p = mpatches.Circle((x, y), 0.2, fc="w") ax.add_patch(p) ax.annotate(to_texstring(stylename), (x, y), (x-1.2, y), ha="right", va="center", size=fontsize, arrowprops=dict(arrowstyle=stylename, patchB=p, shrinkA=5, shrinkB=5, fc="w", ec="k", connectionstyle="arc3,rad=-0.05", ), bbox=dict(boxstyle="square", fc="w")) ax.xaxis.set_visible(False) ax.yaxis.set_visible(False) plt.show() t = np.arange(0.0, 5.0, 0.01) s = np.cos(2*np.pi*t) line, = plt.plot(t, s, lw=2) plt.annotate('local max', xy=(2, 1), xytext=(3, 1.5), arrowprops=dict(arrowstyle='', )) plt.ylim(-2,2) plt.show() bars = plt.bar([1, 2, 3, 4], [10, 12, 15, 17]) plt.setp(bars[0], hatch='x', facecolor='w') plt.show() import matplotlib print matplotlib.matplotlib_fname() import matplotlib as mpl import matplotlib.pyplot as plt mpl.rcdefaults() # for when re-running this cell fig = plt.figure() ax = fig.add_subplot(1, 2, 1) ax.plot([1, 2, 3, 4]) mpl.rcParams['lines.linewidth'] = 2 mpl.rcParams['lines.linestyle'] = '-.' ax = fig.add_subplot(1, 2, 2) ax.plot([1, 2, 3, 4]) plt.show()