matplotlib.pyplot.plot(x, y, marker="Marker type", markerfacecolor="Marker color")
#Data x on the horizontal axis, data y on the vertical axis
# marker="Specifier"If you specify, the marker type (shape) is set.
# markerfacecolor="Specifier"If you specify, the marker color is set.
Specifier | type |
---|---|
"o" | Circle |
"s" | square |
"p" | pentagon |
"*" | Star |
"+" | plus |
"D" | Diamond |
Specifier | color |
---|---|
"b" | Blue |
"g" | Green |
"r" | Red |
"c2 | cyan |
"m" | Magenta |
"y" | yellow |
"k" | black |
"w" | White |
matplotlib.pyplot.plot(x, y, linestyle="Line style", color="Line color")
The treatment of colors is the same as the type of marker.
Specifier | style |
---|---|
"-" | Practice |
"--" | Dashed line |
"-." | Dashed line(Dot) |
":" | dotted line |
matplotlib.pyplot.bar(x, y)
matplotlib.pyplot.bar(x, y, tick_label=[List of labels])
A graph representing two or more series of data stacked for the same item This is called a stacked bar graph.
matplotlib.pyplot.bar(x, y, bottom=[List of data columns])
#If specified, the bottom margin can be set for the corresponding index.
#The series you want to display below when plotting the second and subsequent series
#You can create a stacked bar graph by specifying it as bottom.
plt.legend("Series 1 label", "Series 2 label")
#If specified, the legend can be set.
matplotlib.pyplot.hist(List type data array)
Counting the number of data that fits in each section
It is called the frequency distribution.
When visualizing the frequency distribution, it is called a histogram. Statistical graphs with frequencies (number of times) on the vertical axis and classes (range) on the horizontal axis are often used.
matplotlib.pyplot.hist(List type data column, bins=Number of bins)
#If you specify bins, you can divide into classes with any number of bins.
# bins="auto"If you specify, the number of bins will be set automatically.
When creating a histogram, it is important how many classes the data is divided into. The number of that class
It is called the number of bins.
matplotlib.pyplot.hist(List type data column, density=True)
# density=If True is specified, the histogram can be normalized.
Assuming that the histogram distribution is normal Manipulating the histogram so that the sum is 1 is called normalization or standardization.
matplotlib.pyplot.hist(List type data column, cumulative=True)
# cumulative=If you specify True, you can create a cumulative histogram.
Relative frequency
The frequency expressed as a percentage of the whole
Cumulative relative frequency
Sum of relative frequencies up to that class
The cumulative relative frequency will eventually be 1.
Cumulative histogram
Histogram representation of cumulative relative frequency
You can tell if it is fair by examining the increase or decrease in the cumulative histogram.
matplotlib.pyplot.scatter(x, y)
#Specify the data x on the horizontal axis and the corresponding data y on the vertical axis.
matplotlib.pyplot.scatter(x, y, marker="Marker type", color="Marker color")
#The types and colors are shown in a line graph.
matplotlib.pyplot.scatter(x, y, s=Marker size)
#The default value is 20.
matplotlib.pyplot.scatter(x, y, c=List-type data corresponding to marker color or plot data, cmap="Color system specifier")
# c=You can set the marker color by specifying the marker color
#Specify the list type data corresponding to the lot data in c
#Further cmap="Color system specifier"If you specify, you can display the marker in gradation with the darkness according to the value of c.
Color system specifier | color |
---|---|
"Reds" | Red |
"Blues" | Blue |
"Greens" | Green |
"Purples" | purple |
Be careful of multiple systems.
matplotlib.pyplot.colorbar()
#When you display the color bar, you can see the approximate value by the darkness of the marker.
It corresponds to the right side of the figure below.
matplotlib.pyplot.pie()
#Use this to draw a circle.
matplotlib.pyplot.axis("equal")
#Here's how to make the graph circular, without this code it would be an ellipse.
matplotlib.pyplot.pie(data, labels=[List of labels])
matplotlib.pyplot.pie(data, explode=[List of degree of prominence])
#Any element can be displayed separately.
#Specify a value from 0 to 1 for "Conspicuity" as list type data.
import matplotlib
matplotlib.pyplot.figure().add_subplot(1, 1, 1, projection="3d")
To draw a 3D graph, you need to create a subplot with 3D drawing capabilities Specify projection = "3d" when creating the subplot.
#Subplot is a variable`ax`in the case of
ax.plot_surface(X, Y, Z)
matplotlib.pyplot.show()#The drawn graph is output to the screen using this.
If you want to draw a graph that looks as close to true as possible Draw a curved surface by specifying the data corresponding to the x-axis, y-axis, and z-axis in plot_surface ().
#Subplot is a variable`ax`in the case of
ax.bar3d(xpos, ypos, zpos, dx, dy, dz)
# bar3d()Specify the data corresponding to the x-axis, y-axis, and z-axis positions and the amount of change in
Three-dimensional histograms and bar graphs are effective methods for finding the relationship between two elements. Each element of the dataset corresponds to the x-axis and y-axis, and is stacked in the z-axis direction.
x = np.ravel(X)
#Subplot is a variable`ax`in the case of
ax.scatter3D(x, y, z)
# scatter3D()Specify the data corresponding to the x-axis, y-axis, and z-axis in.
#Because the data you specify must be one-dimensional
#If it is not one-dimensional data, np in advance.ravel()Convert the data using.
A three-dimensional scatter plot has three types of data that are (or are likely to have) related to each other. Plotting in a three-dimensional space is useful for visually predicting trends in data.
#Import cm from matplotlib in advance.
import matplotlib.cm as cm
#Subplot is a variable`ax`in the case of
ax.plot_surface(X, Y, Z, cmap=cm.coolwarm)
#When plotting data, plot_surface()To cmap=cm.If you specify coolwarm
#You can apply a color map to the z-axis values.
3D graphs with monotonous colors may be difficult to see, such as areas with many irregularities. In that case, use the function to change the displayed color according to the coordinates taken by the points in the graph. You can make it easier to see.
Recommended Posts