用matplotlib设置标题、轴标签、刻度标签以及添加图例
2018-04-05 16:39
681 查看
import pandas as pd import numpy as np import matplotlib.pyplot as plt fig=plt.figure() ax=fig.add_subplot(1,1,1) ax.plot(np.random.randn(1000).cumsum()) x_ticks=ax.set_xticks([0,250,500,750,1000]) x_labels=ax.set_xticklabels(["one","two","three","four","five"],rotation=30,fontsize="small") y_ticks=ax.set_yticks([-80,-60,-40,-20,0]) y_labels=ax.set_yticklabels(["one","two","three","four","five"]) ax.set_title("my first matplotlib plot") ax.set_xlabel("stages") ax.set_ylabel("years")plt.show()
#添加图例
fig=plt.figure()
ax1=fig.add_subplot(1,1,1)
ax1.plot(np.random.randn(1000).cumsum(),"k",label="one")
ax1.plot(np.random.randn(1000).cumsum(),"k--",label="two")
ax1.plot(np.random.randn(1000).cumsum(),"k.",label="three")
ax1.legend(loc="best")#ax.legend()或者plt.legend()
plt.show()
相关文章推荐
- 使用matplotlib绘制图像并设置标题以及坐标轴等信息
- Python 3基础教程45-Matplotlib添加标签和标题描述
- 演示MatPlotLib中如何设置坐标轴主刻度标签和次刻度标签
- python matplotlib 画图刻度、图例等字体、字体大小设置
- python matplotlib 画图刻度、图例等字体、字体大小设置
- matplotlib subplots 设置总图的标题
- 使用matplotlib的示例:调整字体-设置刻度、坐标、colormap和colorbar等
- matplotlib给子图添加图例
- matplotlib画子图时设置总标题
- matplotlib给子图添加图例的方法
- python matplotlib绘图设置坐标轴刻度、文本
- 使用matplotlib的示例:调整字体-设置刻度、坐标、colormap和colorbar等
- matplotlib命令与格式:tick坐标轴日期格式(设置日期主副刻度)
- 【Matplotlib】 刻度设置(2)
- matplotlib设置轴标签
- python调用Matplotlib绘制分布点并且添加标签
- matplotlib模块数据可视化-设置图例
- 【原】在Matplotlib绘图过程中设置X轴的刻度和显示文本
- Python利用matplotlib.pyplot绘图时如何设置坐标轴刻度
- Python使用matplotlib模块绘制图像并设置标题与坐标轴等信息示例