matplotlib命令与格式:删除,移动,修改axes脊柱(边框)
来源:互联网 发布:json如何使用 编辑:程序博客网 时间:2024/04/27 18:02
1.关闭坐标轴
plt.axis('off') #关闭xy坐标轴
frame = plt.gca()frame.axes.get_yaxis().set_visible(False) #不显示y轴frame.axes.get_xaxis().set_visible(False) #不显示x轴
例子:
import numpy as npimport matplotlib.pyplot as pltfig, ax = plt.subplots()x = [1, 2, 3, 4, 5]y = [0, 2, 5, 9, 15]plt.plot(x, y)ax.get_yaxis().set_visible(False) #不显示y轴ax.get_xaxis().set_visible(False) #不显示x轴plt.show()
2.spines删除,移动,修改属性
(1)去掉边框线
ax = plt.gca()
ax.spines['top'].set_visible(False) #去掉上边框
ax.spines['bottom'].set_visible(False) #去掉下边框
ax.spines['left'].set_visible(False) #去掉左边框
ax.spines['right'].set_visible(False) #去掉右边框
(2)移动坐标轴(边框)
set_position语法:set_position(type=位置类型,amount=数量)
- outward:place the spine out from the data area by the specified number of points.
- axes: place the spine at the specified Axes coordinate (from 0.0-1.0)
- data:place the spine at the specified data coordinate
#获取当前的坐标轴,ax = plt.gca()# 设置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))
设置x轴, y轴交叉点在(2, 2)的位置
ax.spines['bottom'].set_position(('data', 2))ax.spines['left'].set_position(('data', 2))
#设置坐标轴在axes正中心
ax.spines['top'].set_visible(False) #去掉上边框
ax.spines['right'].set_visible(False) #去掉右边框
ax.spines['bottom'].set_position(('axes',0.5 ))
ax.spines['left'].set_position(('axes', 0.5))
(3)修改边框属性
参考Line2D中set_*命令
设置边框线颜色
ax = plt.gca() # 获取当前的axes
ax.spines['right'].set_color('blue')ax.spines['top'].set_color('none')
设置边框线宽ax1.spines['left'].set_linewidth(5)设置边框线型
ax.spines['left'].set_linestyle('--')
阅读全文
0 0
- matplotlib命令与格式:删除,移动,修改axes脊柱(边框)
- matplotlib命令与格式:设置栅格,axes脊柱(坐标轴),背景颜色
- matplotlib命令与格式:图像(figure)与子区域(axes)布局与规划
- matplotlib命令与格式:图像(figure)与子区域(axes)布局与规划
- matplotlib.axes.Axes.plot
- matplotlib : axes.scatter
- matplotlib.axes.Axes.errorbar 误差bar图像
- matplotlib命令与格式:axis坐标轴对象命令合集
- matplotlib命令与格式:tick刻度对象命令合集
- matplotlib命令与格式:系统字体与显示中文
- matplotlib命令与格式:设置折线与点属性
- matplotlib命令与格式:参数配置文件与参数配置
- matplotlib命令与格式:图例legend语法及设置
- matplotlib命令与格式:标题(title),标注(annotate),文字说明(text)
- matplotlib命令与格式:pyplot api坐标轴刻度常用命令
- matplotlib命令与格式:tick_params参数刻度线样式设置
- matplotlib命令与格式:tick坐标轴主副刻度设置
- matplotlib命令与格式:坐标轴数值格式(日期格式,百分比,科学记数)
- Octotree Chrome安装与使用方法
- 背包思想衍生算法
- golang学习之Interface类型断言
- react-native node解决tar ENOENT: no such file or directory, open '/node_modules/.staging/react-native-
- 移除VMWARE VIEW中孤立主机与桌面池的方法(转)
- matplotlib命令与格式:删除,移动,修改axes脊柱(边框)
- 每天一个linux命令(58):telnet命令
- sendRedirect()之后的代码是否会继续执行
- W
- 翻转句子
- Java Reflection 反射教程 [转]
- queue list
- 三次握手的第三个ACK包丢了,会发生什么?
- TOMCAT虚拟目录配置