折线图
import matplotlib.pyplot as plt
import numpy as np
N=100
x_data=np.random.rand(N)
y_data=np.random.rand(N)
def lineplot(x_data, y_data, x_label="", y_label="", title=""):
_, ax = plt.subplots()
ax.plot(x_data, y_data, lw = 2, color = '#539caf', alpha = 1)
ax.set_title(title)
ax.set_xlabel(x_label)
ax.set_ylabel(y_label)
plt.show()
lineplot(x_data,y_data,x_label="x_label",y_label="y_label", title="title")
直方图
import matplotlib.pyplot as plt
import numpy as np
N=100
x_data=np.random.rand(N)
n_bins = 10
def histogram(x_data, n_bins, cumulative=False, x_label = "", y_label = "", title = ""):
fig, ax = plt.subplots()
ax.hist(x_data, n_bins, cumulative = cumulative, color = '#539caf')
ax.set_ylabel(y_label)
ax.set_xlabel(x_label)
ax.set_title(title)
fig.savefig('fig.png')
plt.show()
histogram(x_data,n_bins,x_label='i am x', title='iam title')