#9 Going through Matplotlib package in Python
In this journal, we are going to go through the visual package in Python calls Matplotlib. We can install this package from pip. We also import numpy package as np in order to create the data for drawing the graphs. We will get to know 2 popular functions in Matplotlib are plot() and scatter().
- Plot function: uses to draw the points in diagram. We need 2 parameters to create a plot graph, parameter 1 is assigned is the points on the x-axis, parameter 2 is assigned is the points on the y-axis. Besides the basic graph, we can elaborate them with marker or change the color of line in order to improve its appearance.
For marker, we have 'o' for circle, '*' for star, '.' for point, and so on. For line display, we have ':' for dotted line, '-' for solid line, '--' dashed line, and '-.' for dashed/dotted line. For color, we have 'r' for red, 'b' for blue, 'g' for green, 'k' for black', 'w' for white, and so on. It looks super cool, isn't it?
We also can use linewidth to increase our line size, 'ms' stands for marker size, 'mec' stands for marker edge color, and 'mfc' stands for marker face color. These parameters are actually helpful when we try to make the difference between 2 or multiple lines on the same diagram.
- Subplots: we use subplots to display the multiple plots in one figure. We use function plt.subplot( a, b , c), with a means the rows, b means the columns, and c means the position of the graph. We also can label them with title as normal in plot graph.
- Scatter: Instead of plot, we also can use scatter to display our data with function plt.scatter(). It has some useful parameters such as: s for size, alpha for transparency, cmap for colorbar, and so on. We also can combinate both scatter and plot for our graphs, it depends on how we want to visualize our data.
I think visualization data is a very important tool, it helps us easily display and evaluate our model efficiently, especially with large amounts of complex data.






Bao,
ReplyDeleteNice work this week with the matplotlib package.