一、设置图表样式与映射表
(1)使用rc()函数修改图表样式
(2)设置颜色映射表可以使用关键字cmap或者直接调用set_cmap()函数进行设置
1、代码
import numpy as np
import matplotlib.pyplot as plt
plt.rcParams["font.sans-serif"] = ["SimHei"]
plt.rcParams["axes.unicode_minus"] = False
x = np.arange(5)
y1 = [1200, 2400, 1800, 2200, 1600]
y2 = [1050, 2100, 1300, 1600, 1340]
bar_width = 0.6
tick_label = ["家庭", "小说", "心理", "科技", "儿童"]
fig = plt.figure()
ax = fig.add_subplot(111)
ax.bar(x, y1, bar_width, color="b", align="center", label ="地区1")
ax.bar(x, y2, bar_width, bottom=y1, color="c", align="center", label="地区2")
ax.set_ylabel("采购数量(本)")
ax.set_xlabel("图书种类")
ax.set_title(" 地区1和地区2对各类图书的采购情况")
ax.grid(True, axis='y', color="gray", alpha=0.2)
ax.set_xticks(x)
ax.set_xticklabels(tick_label)
ax.legend()
plt.show()
效果如图
二、选择线型
(1)线型取值“:’,’-.’,’–’,’-’”四种
表示方法plt.plot(…,linestyle=’–’)或者plt.plot(…,ls=’–’)
1、代码
import numpy as np
import matplotlib.pyplot as plt
plt.rcParams["font.sans-serif"] = ["SimHei"]
plt.rcParams["axes.unicode_minus"] = False
eurcny_2017 = np.array([6.8007, 6.8007, 6.8015, 6.8015, 6.8060, 6.8060, 6.8060, 6.8036,
6.8025, 6.7877, 6.7835, 6.7758, 6.7700, 6.7463, 6.7519,6.7511,
6.7511,