Matplotlib is a powerful data visualization library that allows you to create various types of plots. In this article, we will discuss the basics of creating line plots, scatter plots, and bar plots using Matplotlib.
Line Plots: To create a line plot, you can use the plot
function from Matplotlib. Here's an example:
data = [1, 2, 3, 4, 5]
plt.plot(data)
plt.show()
Scatter Plots: Scatter plots are useful to visualize the relationship between two variables. You can create a scatter plot using the scatter
function. Here's an example:
data_x = [1, 2, 3, 4, 5]
data_y = [3, 4, 2, 1, 5]
plt.scatter(data_x, data_y)
plt.show()
Bar Plots: Bar plots are commonly used to compare different categories. You can create a bar plot using the bar
or barh
function. Here's an example using the bar
function:
categories = ['A', 'B', 'C', 'D']
data = [10, 15, 7, 12]
plt.bar(categories, data)
plt.show()
These are just the basic examples of creating plots with Matplotlib. There are many customization options available to further enhance your plots. Keep exploring and have fun with Matplotlib!