matplotlib的基本用法(三)——调整坐标轴
2017-04-29 11:53
627 查看
文章作者:Tyan
博客:noahsnail.com | CSDN | 简书
本文主要是关于matplotlib的一些基本用法。
Demo
结果
博客:noahsnail.com | CSDN | 简书
本文主要是关于matplotlib的一些基本用法。
Demo
import matplotlib.pyplot as plt import numpy as np # 绘制普通图像 x = np.linspace(-1, 1, 50) y1 = 2 * x + 1 y2 = x**2 plt.figure() plt.plot(x, y1) plt.plot(x, y2, color = 'red', linewidth = 1.0, linestyle = '--') # 设置坐标轴的取值范围 plt.xlim((-1, 1)) plt.ylim((0, 2)) # 设置坐标轴的lable plt.xlabel('X axis') plt.ylabel('Y axis') # 设置x坐标轴刻度, 原来为0.25, 修改后为0.5 plt.xticks(np.linspace(-1, 1, 5)) # 设置y坐标轴刻度及标签, $$是设置字体 plt.yticks([0, 0.5], ['$minimum$', 'normal']) # 获取当前的坐标轴, gca = get current axis ax = plt.gca() # 设置右边框和上边框 ax.spines['right'].set_color('none') ax.spines['top'].set_color('none') # 设置x坐标轴为下边框 ax.xaxis.set_ticks_position('bottom') # 设置y坐标轴为左边框 ax.yaxis.set_ticks_position('left') # 设置x轴, y周在(0, 0)的位置 ax.spines['bottom'].set_position(('data', 0)) ax.spines['left'].set_position(('data', 0)) plt.show()
结果
参考资料
https://www.youtube.com/user/MorvanZhou相关文章推荐
- matplotlib的基本用法(二)——设置坐标轴
- matplotlib的基本用法(十五)——主次坐标轴
- matplotlib的基本用法(六)——设置坐标轴label
- matplotlib的基本用法(七)——绘制散点图
- matplotlib的基本用法(十二)——subplot绘制多图
- scatter 基本用法 python matplotlib
- matplotlib的基本用法(十六)——创建动画
- matplotlib的基本用法(八)——绘制柱状图
- matplotlib数据展现的基本用法
- matplotlib的基本用法(一)——figure的使用
- matplotlib的基本用法(十四)——figure图的嵌套
- matplotlib的基本用法(十七)——保存figure
- matplotlib的基本用法(十一)——绘制3D图
- matplotlib的基本用法(十三)——figure绘制多图
- 使用matplotlib的示例:调整字体-设置刻度、坐标、colormap和colorbar等
- python matplotlib 入门系列一:基本用法
- matplotlib的基本用法(十)——绘制Image
- 使用matplotlib的示例:调整字体-设置刻度、坐标、colormap和colorbar等
- matplotlib的基本用法(四)——设置legend图例
- matplotlib的基本用法(九)——绘制等高线图