This time I studied matplotlib, so I will output it.
An external library that visualizes data. Like numpy and pandas, it is not included in Python at first, but it is installed in Anaconda from the beginning.
You can quickly find outliers.
For example, let's say you have statistics on the price of sweets. It would be strange if there was data on sweets for 10,000 yen each among sweets for around 100 yen each, right? It is very difficult to find the strange data instantly, but you can find it instantly by visualizing the data with a graph or the like.
Is there only one strange point here? (Laughs)
test.ipynb
#Import matplotlib
import matplotlib.pyplot as plt
%matplotlib inline
Let's do the above. Use% matplotlib inline only when using it with Jupyter Notebook. This time, only the function of pyplot is used, so only pyplot is imported.
test.ipynb
#Graph size setting(4×4)
plt.figure(figsize=(4,4))
#Creating a graph
plt.plot([1,2,3,4,5],[6,7,8,9,10],label='test')
#x-axis name
plt.xlabel('x axis')
#y-axis name
plt.ylabel('y axis')
#Graph title
plt.title('title')
#Reflect the above legend in the graph
plt.legend()
#Show graph
plt.show()
The basic function is above. Even if you do not describe plt.show (), the graph will be displayed, so please feel free to use it.
If you want to describe the graph of x squared, ...
test.ipynb
import numpy as np
#1~Substitute an array of 10 into x
x = np.arange(0,11,1)
#Make the value of y the square of x
y = x ** 2
plt.plot(x,y,label='y = x^2')
#x-axis name
plt.xlabel('x axis')
#y-axis name
plt.ylabel('y axis')
#Graph title
plt.title('y = x^2')
#Reflect the above legend in the graph
plt.legend()
#Show graph
plt.show()
You can do it with this.
The following describes how to display multiple graphs.
test.ipynb
#Create a graph with a total size of 8 x 8 in 2 rows and 2 columns
fig,ax = plt.subplots(2,2,figsize=(8,8))
#x,y,Set the z range
x = np.arange(0,11,1)
y = x ** 2
z = x ** 3
#Creating a graph
ax[0,0].plot(x,x,label='x = x',color='red')
ax[0,1].plot(x,y,label='y = x^2'),color='green')
ax[1,0].plot(x,z,label='z = x^3'),color='blue')
#Graph settings
for i in range(2):
for j in range(2):
ax[i,j].set_xlabel('x axis')
ax[i,j].set_ylabel('y axis')
ax[i,j].legend()
plt.tight_layout()
Create a graph of 8 sizes vertically and horizontally in the entire size in fig Four graphs of two sizes, vertical and horizontal, are created in it.
The tight_layout function is a function that prevents graphs from overlapping each other.
Until now, it was only a bar graph, but of course you can create other graphs.
test.ipynb
#pie chart
plt.pie()
#histogram
plt.hist()
#Scatter plot
plt.scatter()
Arguments are omitted, but pie charts and histograms show the ratio and transition of each data. The scatter plot is used to check the set data, so if you are interested, please check it out!
Machine learning I've been here so far, but it's fun! I haven't spoken a language that allows me to do various things like this, so it's nice to be able to do many things. I'll post it in the output tomorrow and beyond, but don't miss it ...
that's all
Recommended Posts