# Let printing work the same in Python 2 and 3 from __future__ import print_function # Turning on inline plots -- just for use in ipython notebooks. %matplotlib inline import numpy as np import matplotlib.pyplot as plt t = np.arange(0.0, 5.0, 0.2) plt.plot(t, t, , t, t**2, , t, t**3, ) plt.show() xs, ys = np.mgrid[:4, 9:0:-1] markers = [".", "+", ",", "x", "o", "D", "d", "", "8", "s", "p", "*", "|", "_", "h", "H", 0, 4, "<", "3", 1, 5, ">", "4", 2, 6, "^", "2", 3, 7, "v", "1", "None", None, " ", ""] descripts = ["point", "plus", "pixel", "cross", "circle", "diamond", "thin diamond", "", "octagon", "square", "pentagon", "star", "vertical bar", "horizontal bar", "hexagon 1", "hexagon 2", "tick left", "caret left", "triangle left", "tri left", "tick right", "caret right", "triangle right", "tri right", "tick up", "caret up", "triangle up", "tri up", "tick down", "caret down", "triangle down", "tri down", "Nothing", "Nothing", "Nothing", "Nothing"] fig, ax = plt.subplots(1, 1, figsize=(14, 4)) for x, y, m, d in zip(xs.T.flat, ys.T.flat, markers, descripts): ax.scatter(x, y, marker=m, s=100) ax.text(x + 0.1, y - 0.1, d, size=14) ax.set_axis_off() plt.show() t = np.arange(0.0, 5.0, 0.2) plt.plot(t, t, , t, t**2, , t, t**3, ) plt.show() 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() """ 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) 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 styles = mpatches.ArrowStyle.get_styles() ncol=2 nrow = (len(styles)+1) // ncol figheight = (nrow+0.5) fig = plt.figure(1, (4.0*ncol/0.85, figheight/0.85)) fontsize = 0.4 * 70 ax = fig.add_axes([0, 0, 1, 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=50, shrinkB=5, fc="w", ec="k", connectionstyle="arc3,rad=-0.25", ), bbox=dict(boxstyle="square", fc="w")) ax.set_axis_off() 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, (ax1, ax2) = plt.subplots(1, 2) ax1.plot([1, 2, 3, 4]) mpl.rc('lines', linewidth=2, linestyle='-.') # Equivalent older, but still valid syntax #mpl.rcParams['lines.linewidth'] = 2 #mpl.rcParams['lines.linestyle'] = '-.' ax2.plot([1, 2, 3, 4]) plt.show()