Mtplotlib-rookie tutorial-chart example 1

line chart

Insert picture description here
import pandas as pd
import matplotlib.pyplot as plt
iris = pd.read_csv(‘iris.csv’)
fig = plt.figure(figsize = (10, 10))
plt.plot(iris[‘sepal_width’],‘r–’,label=‘sepal_width’)
plt.legend(loc=‘best’)

Scatter plot

Insert picture description here
import pandas as pd
import matplotlib.pyplot as plt
iris = pd.read_csv('iris.csv')
fig = plt.figure(figsize = (10, 10))
plt.scatter(iris['sepal_length'],iris[' petal_length'],label='petal&sepal_length')
plt.legend(loc='best')//The system automatically takes the most suitable value
plt.xlabel('sepal_length')//Set the x-axis
plt.ylabel('petal_length')

Histogram

Insert picture description here
import pandas as pd
import matplotlib.pyplot as plt
iris = pd.read_csv(‘iris.csv’)
fig = plt.figure(figsize = (10, 10))
plt.hist(iris[‘petal_width’],label=‘petal_width’)
plt.legend(loc=‘best’)

Box plot

Insert picture description here
import pandas as pd
import matplotlib.pyplot as plt
iris = pd.read_csv('iris.csv')
fig = plt.figure(figsize = (10, 10))
plt.boxplot(iris['petal_length'])
plt.title ('box plot') //Set the title
plt.ylabel('data content') //Set the axis name

Guess you like

Origin blog.csdn.net/weixin_44039266/article/details/105373501