import matplotlib.pyplot as plt
import pandas
# this bag will not be used later but it's my habit to import it
import numpy as np
x = np.linspace(0,2,100) # plot the x_axes into 100,and the range is from0 to 100
fig, ax = plt.subplots() # create a coordinate system
ax.plot(x, x, label="linear") # this is the formation of(O,O,style)
ax.plot(x, x**2, label="quadratic")
ax.plot(x, x**3, label="cubic")
# ax.plot(x, x**x, label='unkown')
ax.set_xlabel("x_label") # plot 'x_label' to x_axes
ax.set_ylabel("y_label")
ax.set_title("multi-xy")
ax.legend() # plot legend to this ax
plt.show()
第二种方法pyplot-style
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0,2,100)
plt.plot(x, x, label='linear') # plot some data in the implicit axes
plt.plot(x, x**2, label='quadratic')
plt.plot(x, x**3, label='cubic')
plt.xlabel('x_label')
plt.ylabel('y_label')
plt.title('multi-xy')
plt.legend()
plt.show()
今天的最后一个知识点
import matplotlib.pyplot as plt
import pandas # this bag will not be used later but it's my habit to import it
import numpy as np
def my_plotter(ax, data1, data2, param_dict):
out = ax.plot(data1, data2,**param_dict)return out
data1, data2, data3, data4 = np.random.rand(4,100)
fig, ax = plt.subplots(1,1) # create a axes
my_plotter(ax, data1, data2,{'marker':'x'})
plt.show()