Plotting Using Matplotlib Pyplot
Published on 02 Aug 2017
There are at least two ways to plotting in matplotlib; ## 1. Using pyplot wrapper functions fig = plt.figure(1, figsize=(12,3)) #ax = fig.gca() #ax.set_axis_off() for i in range(16): plt.subplot(2, 8, i+1) x = data_a[i] plt.imshow(x+0.5, cmap='gray', aspect='auto') #plt.axis('off') #plt.title('A') plt.yticks([]) plt.xticks([]) fig.tight_layout() # Try with and without this plt.show() ## 2. Using object oriented approach to matplotlib Here pyplot is used only to get access to the axes numpy array of axis objects. The rest are directly operated on the axes objects. [Reference: Matplotlib](http://matplotlib.org/faq/usage_faq.html#coding-styles) # Object oriented approach fig, axes = plt.subplots(2, 8, figsize=(12, 3)) fig.tight_layout() # Try with and without this # Make your plot, set your axes labels for i in range(16): ax = axes[i/8][i%8] if i/8 == 0: x = data_a[i] ax.set_ylabel('A') else: x = data_b[i] ax.set_ylabel('B') ax.imshow(x, cmap='gray', aspect='auto') # Turn off tick labels ax.set_yticklabels([]) ax.set_xticklabels([]) plt.show() ### Sample Output ![Image](https://dl.dropboxusercontent.com/s/uwlep366xigvuur/notMNIST.png) ## Plot shaded confidence interval https://stackoverflow.com/questions/12957582/matplotlib-plot-yerr-xerr-as-shaded-region-rather-than-error-bars ## About Legends https://matplotlib.org/gallery/text_labels_and_annotations/custom_legends.html#sphx-glr-gallery-text-labels-and-annotations-custom-legends-py