
> axes.quiver(y,z) #Plot a 2D field of arrows > axes2= ax.clabel(CS) #Label a contour plot Vector Fields > axes.arrow(0,0,0.5,0.5) #Add an arrow to the axes > axes2.pcolormesh(data) #Pseudocolor plot of 2D array > axes2.pcolor(data2) #Pseudocolor plot of 2D array > im = ax.imshow(img, #Colormapped or RGB arrays

> ax.fill_between(x,y,color='yellow') #Fill between y values and 0 2D Data > fig, ax = plt.subplots() > ax.fill(x,y,color='blue') #Draw filled polygons > axes.axvline(0.65) #Draw a vertical line across axes > axes.axhline(0.45) #Draw a horizontal line across axes > axes.barh(,) #Plot horiontal rectangles (constant height) > axes.bar(,) #Plot vertical rectangles (constant width) > ax.scatter(x,y) #Draw unconnected points, scaled or colored > lines = ax.plot(x,y) #Draw points with lines or markers connecting them

> plt.savefig('foo.png', transparent=True) #Save transparent figures Show Plot > plt.show() Plotting Routines 1D Data > fig, ax = plt.subplots() > fig4, axes2 = plt.subplots(ncols=3) Save Plot > plt.savefig('foo.png') #Save figures > fig3, axes = plt.subplots(nrows=2,ncols=2) > ax1 = fig.add_subplot(221) #row-col-num

> fig2 = plt.figure(figsize=plt.figaspect(2.0)) Axes > fig.add_axes() > img = np.load(get_sample_data('axes_grid/bivariate_normal.npy')) Create Plot > import matplotlib.pyplot as plt Figure > fig = plt.figure() > from matplotlib.cbook import get_sample_data > z = np.sin(x) 2D Data or Images > data = 2 * np.random.random((10, 10)) Prepare the Data 1D Data > import numpy as np Matplotlib is a Python 2D plotting library which produces publication-quality figures in a variety of hardcopy formats and interactive environments across platforms. What might have looked difficult before will definitely be more clear once you start using this cheat sheet! Use it in combination with the Matplotlib Gallery, the documentation and our tutorial.Īlso, don't miss out on our other cheat sheets for data science that cover SciPy, Numpy, Scikit-Learn, Bokeh, Pandas and the Python basics.

With this handy reference, you'll familiarize yourself in no time with the basics of Matplotlib: you'll learn how you can prepare your data, create a new plot, use some basic plotting routines to your advantage, add customizations to your plots, and save, show and close the plots that you make. You'll see that this cheat sheet presents you with the six basic steps that you can go through to make beautiful plots.Ĭheck out the infographic by clicking on the button below: (By the way, if you want to get started with this Python package, you might want to consider our Matplotlib tutorial.)
#Clear scatter plot matplotlib how to
Of course, for those who don't know how to work with Matplotlib, this might be the extra push be convinced and to finally get started with data visualization in Python. There is so much that you can do with it and it might be hard to still keep a structure when you're learning how to work with Matplotlib.ĭataCamp has created a Matplotlib cheat sheet for those who might already know how to use the package to their advantage to make beautiful plots in Python, but that still want to keep a one-page reference handy. However, what might slow down beginners is the fact that this package is pretty extensive. But, what might be even more convincing is the fact that other packages, such as Pandas, intend to build more plotting integration with Matplotlib as time goes on. Data visualization and storytelling with your data are essential skills that every data scientist needs to communicate insights gained from analyses effectively to any audience out there.įor most beginners, the first package that they use to get in touch with data visualization and storytelling is, naturally, Matplotlib: it is a Python 2D plotting library that enables users to make publication-quality figures.
