x = np.array([10, 8, 13, 9, 11, 14, 6, 4, 12, 7, 5]) y = np.array([8.04, 6.95, 7.58, 8.81, 8.33, 9.96, 7.24, 4.26, 10.84, 4.82, 5.68]) plt.plot(x, y, 'o') plt.xlabel('x') plt.ylabel('y') plt.title('Anscombe dataset') a, b = np.polyfit(x, y, 1) plt.plot(x, y, 'o') plt.plot(x, a * x + b, '-') xvec = np.array([[10, 8, 13, 9, 11, 14, 6, 4, 12, 7, 5], [10, 8, 13, 9, 11, 14, 6, 4, 12, 7, 5], [10, 8, 13, 9, 11, 14, 6, 4, 12, 7, 5], [8,8,8,8,8,8,8,19,8,8,8]]).T yvec = np.array([[8.04, 6.95, 7.58, 8.81, 8.33, 9.96, 7.24, 4.26, 10.84, 4.82, 5.68], [9.14, 8.14, 8.74, 8.77, 9.26, 8.10, 6.13, 3.10, 9.13, 7.26, 4.74], [7.46, 6.77, 12.74, 7.11, 7.81, 8.84, 6.08, 5.39, 8.15, 6.42, 5.73], [6.58, 5.76, 7.71, 8.84, 8.47, 7.04, 5.25, 12.50, 5.56, 7.91, 6.89]]).T plt.plot(xvec, yvec, 'o'); plt.title('length') plt.bar(x, y, 1) plt.title('position and color') plt.scatter(x, y, c=y, s=100) plt.title('position and size') plt.scatter(x, y, s=y*20, facecolor='none') theta = (x - x.min())*1./(x.max()-x.min())*2*np.pi theta = np.vstack([theta, theta]) radius = np.vstack([np.zeros(len(y)), y]) plt.polar(theta, radius, 'b'); plt.plot(x, y, 'o', markersize=10, mfc='k') plt.xlabel('x', size=16) plt.ylabel('y', size=16) plt.title('Anscombe dataset', size=16, weight='bold') rc_defaults = matplotlib.rcParams.copy() import matplotlib matplotlib.rcParams.update({'xtick.labelsize' : 16, 'ytick.labelsize' : 16, 'axes.labelsize' : 16, 'axes.titlesize' : 18, 'lines.markersize' : 10, 'lines.linestyle' : 'None', 'lines.marker' : 'o', 'lines.markerfacecolor' : 'k'}) plt.plot(x, y) plt.xlabel('x') plt.ylabel('y') plt.title('Anscombe dataset') matplotlib.rcParams.update(rc_defaults) ax = plt.subplot(111) line, = plt.plot(x, y, 'o') line.set_markersize(10) line.set_mfc('k') ticklabels = ax.get_xticklabels() ticklabels[0].set_size(15) ticklabels[-1].set_size(15) plt.setp(ticklabels[1:-1], visible=False) plt.plot(x, y, 'ko') plt.grid(axis='y', which='major', ls='-', lw=0.5) ax = plt.subplot(111) plt.plot(x, y, 'ko', ms=10, clip_on=False) ax.spines['top'].set_visible(False) ax.spines['right'].set_visible(False) ax.spines['bottom'].set_position(('outward', 20)) ax.spines['left'].set_position('center') ax.xaxis.set_ticks_position('bottom') ax.yaxis.set_ticks_position('left') p1, = plt.plot(xvec[:,0], yvec[:, 0], 'bo', label='dataset 1') p2, = plt.plot(xvec[:,1], yvec[:, 1], 'ro', label='dataset 2') #inset legend l1 = plt.legend(frameon=False, loc='lower right') #external legend l2 = plt.legend((p1, p2), ('new label 1', 'new label 2'), ncol=2, numpoints=1, loc='upper left', bbox_to_anchor=(0, -0.1)) plt.gca().add_artist(l1) # re-insert inset legend ax = plt.subplot(111) plt.plot(x, y, 'bo') plt.text(5, 9, 'Text in\ndata coords', transform=ax.transData, # data coordinates (default) size=15) plt.text(0.8, 0.1, 'Text in\naxes coords', transform=ax.transAxes, # axes coordinates size=15, ma='right', ha='right') ax = plt.subplot(111) plt.plot(xvec[:,2], yvec[:,2], 'ko') ax.annotate("Outlier", xy=(13, 12.74), xycoords='data', xytext=(10, 11.5), textcoords='data', fontsize=12, arrowprops=dict(arrowstyle="->", color='r', shrinkA=2, shrinkB=5, connectionstyle='angle,angleA=180,angleB=45,rad=0' ) ) plt.imshow(yvec.T, interpolation='nearest', cmap='gray') plt.colorbar(orientation='horizontal') fig, axes = plt.subplots(nrows=3, figsize=(6,2)) fig.subplots_adjust(hspace=0.4) c = np.linspace(0, 1, 50)[None, :] cmaps = [('Sequential','PuBu'), ('Diverging', 'RdBu'), ('Qualitative', 'Accent')] for ax, (cname, cmap) in zip(axes, cmaps): ax.imshow(c, interpolation='nearest', aspect='auto', cmap=cmap) ax.set_ylabel(cname, rotation=0) ax.set_xticks([]) ax.set_yticks([]) from matplotlib import colors cmap1 = colors.LinearSegmentedColormap.from_list('smooth', ['r', 'y', 'b']) cmap2 = colors.LinearSegmentedColormap.from_list('segmented', ['r', 'y', 'b'], N=6) fig, axes = plt.subplots(nrows=2, figsize=(6,1)) for ax, cmap in zip(axes, [cmap1, cmap2]): ax.imshow(c, interpolation='nearest', aspect='auto', cmap=cmap) ax.set_xticks([]), ax.set_yticks([]) ax.set_ylabel(cmap.name, rotation=0) def cmap_discretise(cmap, n_levels): original_cmap = plt.get_cmap(cmap) colors_i = np.concatenate((np.linspace(0, 1., n_levels), (0.,0.,0.,0.))) colors_rgba = original_cmap(colors_i) indices = np.linspace(0, 1., n_levels+1) cdict = {} for ki,key in enumerate(('red','green','blue')): cdict[key] = [(indices[i], colors_rgba[i-1,ki], colors_rgba[i,ki]) for i in xrange(n_levels+1)] discrete_cmap = colors.LinearSegmentedColormap('discrete', cdict, 1024) return discrete_cmap fig, (ax1, ax2) = plt.subplots(ncols=2, figsize=(10, 5)) cmap = cmap_discretise('PuBu', 4) img1 = ax1.imshow(yvec.T, interpolation='nearest', cmap='PuBu') img2 = ax2.imshow(yvec.T, interpolation='nearest', cmap=cmap) fig, (ax1, ax2) = plt.subplots(ncols=2, sharey=True, figsize=(8,4)) ax1.plot(xvec[:, 1], yvec[:, 1], 'ko') ax2.plot(xvec[:, 2], yvec[:, 2], 'ko') from matplotlib import gridspec gs = gridspec.GridSpec(4,4) for i in range(4): for j in range(4): if i == j: continue ax = plt.subplot(gs[i, j]) ax.plot(yvec[:, i], yvec[:, j], '.') plt.setp(ax.get_xticklabels(), visible=False) plt.setp(ax.get_yticklabels(), visible=False) gs = gridspec.GridSpec(2, 2) gs_topright = gridspec.GridSpecFromSubplotSpec(2, 2, gs[0,0], wspace=0.4, hspace=0.4) for i in range(3): plt.subplot(gs[i+1]) for i in range(4): plt.subplot(gs_topright[i])