Exploring plot types
We have looked at how to create simple line plots so far. The matplotlib library supports many more plot types that are useful for data visualization. However, our goal is to provide the basic knowledge that will help you to understand and use the library for visualizing data in the most common situations. Therefore, we will only focus on four kinds of plot types: scatter plots, bar plots, contour plots, and histograms.
Scatter plots
A scatter plot is used to visualize the relationship between variables measured in the same dataset. It is easy to plot a simple scatter plot, using the plt.scatter()
function, that requires numeric columns for both the x
and y
axis:
Let's take a look at the command for the preceding output:
>>> X = np.random.normal(0, 1, 1000) >>> Y = np.random.normal(0, 1, 1000) >>> plt.scatter(X, Y, c = ['b', 'g', 'k', 'r', 'c']) >>> plt.show()
Bar plots
A bar plot is used to present grouped data with rectangular bars,...