b站网课
官方文档
另一个好用的在线画图工具是百度的echarts
plotly python
1.绘制折线图
from matplotlib import pyplot as plt
import matplotlib
x = range(2, 28, 2)
# x = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26]
y = [15, 13, 14, 5, 17, 20, 25, 26, 26, 24, 22, 18, 15]
y_2 = [i / 2 for i in y]
my_font = {'family': 'monospace',
'weight': 'bold',
'size': 20}
plt.rc('font', **my_font)
# dpi:dots per inch
fig = plt.figure(figsize=(20, 10), dpi=80)
plt.plot(x, y, label="curve1", color="red", ls=':', lw='5')
plt.plot(x, y_2, label="curve2", color="green", ls='-.')
# set x and y axis
# plt.xticks(x)
# plt.xticks(range(0, 30, 1))
_xticks_label = ["hello,{}".format(i) for i in x]
plt.xticks(x, _xticks_label, rotation=45)
plt.yticks(range(0, 30, 1))
plt.xlabel("x axis", fontproperties=my_font)
plt.ylabel("y axis", fontproperties=my_font)
plt.title("title", fontproperties=my_font)
# grid and its transparency
plt.grid(alpha=0.25, ls='--')
plt.legend(prop=my_font, loc="best")
plt.savefig("./t1.png")
plt.show()
2.绘制散点图
plt.scatter(x, y, label="curve2", color="red")
plt.scatter(x, y_2, label="curve2", color="green")
3.绘制条形图
纵向
plt.bar(x, y, label="curve2", color="red", width=0.4)
plt.bar(x, y_2, label="curve2", color="green", width=0.2)
横向
plt.barh(x, y, label="curve2", color="red",height=0.4)
plt.barh(x, y_2, label="curve2", color="green")
绘制多个纵向条形图: