matplotlib的基本用法(六)——设置坐标轴label
2017-04-30 15:23
911 查看
文章作者:Tyan
博客:noahsnail.com | CSDN | 简书
本文主要是关于matplotlib的一些基本用法。
Demo
结果
![](http://ocs628urt.bkt.clouddn.com/m6.png)
博客:noahsnail.com | CSDN | 简书
本文主要是关于matplotlib的一些基本用法。
Demo
import matplotlib.pyplot as plt import numpy as np # 绘制普通图像 x = np.linspace(-3, 3, 50) y = 2 * x + 1 plt.figure() plt.plot(x, y) # 将上、右边框去掉 ax = plt.gca() ax.spines['right'].set_color('none') ax.spines['top'].set_color('none') # 设置x轴的位置及数据在坐标轴上的位置 ax.xaxis.set_ticks_position('bottom') ax.spines['bottom'].set_position(('data', 0)) # 设置y轴的位置及数据在坐标轴上的位置 ax.yaxis.set_ticks_position('left') ax.spines['left'].set_position(('data', 0)) # 设置坐标轴label的大小,背景色等信息 for label in ax.get_xticklabels() + ax.get_yticklabels(): label.set_fontsize(12) label.set_bbox(dict(facecolor = 'green', edgecolor = 'None', alpha = 0.7)) plt.show()
结果
![](http://ocs628urt.bkt.clouddn.com/m6.png)
参考资料
https://www.youtube.com/user/MorvanZhou相关文章推荐
- matplotlib的基本用法(二)——设置坐标轴
- matplotlib的基本用法(三)——调整坐标轴
- matplotlib的基本用法(四)——设置legend图例
- matplotlib的基本用法(十五)——主次坐标轴
- 演示MatPlotLib中如何设置坐标轴主刻度标签和次刻度标签
- matplotlib的基本用法(一)——figure的使用
- matplotlib的基本用法(十七)——保存figure
- matplotlib的基本用法(八)——绘制柱状图
- Matplotlib 绘图双纵坐标轴设置及控制设置时间格式
- 【Matplotlib】线设置,坐标显示范围
- 【Matplotlib】线设置,坐标显示范围
- matplotlib画图坐标轴设置
- matplotlib的基本用法(十三)——figure绘制多图
- matplotlib的基本用法(十)——绘制Image
- python matplotlib绘图设置坐标轴刻度、文本
- matplotlib的基本用法(十一)——绘制3D图
- matplotlib的基本用法(五)——添加annotation
- 使用matplotlib的示例:调整字体-设置刻度、坐标、colormap和colorbar等
- matplotlib的基本用法(七)——绘制散点图
- 使用matplotlib的示例:调整字体-设置刻度、坐标、colormap和colorbar等