matplotlib 画折线图,部分参数问题

matplotlib画折线图参数及释义
import matplotlib.pyplot as plt

x = [1,2,3,6]
y = [2,4,9,7]
# plt.style.use('ggplot')   # 添加样式
plt.rcParams['font.sans-serif'] = ['Songti SC']    # 显示中文字体
# plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False    # 显示特殊字符

plt.figure(figsize=(13, 8))  # 定义图片储存大小
# legend = plt.legend(title="510500ETF")    定义子标题
# legend._legend_box.align = "left"    # 居左,居中(center),居右(right)
# plt.title('title:', loc='left', fontsize=30, color='lightsteelblue')
# plt.ylabel('price', fontsize=10)
# plt.xlabel("date")

plt.plot(x, y, 'd-', linewidth=3, alpha=0.9, markersize=3, label='Closing price')  # g:green, o:焦点, --:连线用虚线
plt.xticks(rotation=45, fontsize=10)    # x轴旋数据转角度
# plt.legend()    # label='Closing price'    定义折现说明,和plot里的label挂钩
# plt.subplots_adjust(top=1, bottom=0, left=0, right=1, hspace=5, wspace=5)
# plt.margins()
plt.grid(axis='y')  # 底纹
# plt.show()
plt.savefig(figfile, format='png', bbox_inches='tight', pad_inches=0)    # 参数bbox_inches='tight', pad_inches=0, 保存时去除空白边框

  

posted @ 2022-01-10 19:44  小王八+1  阅读(93)  评论(0编辑  收藏  举报