matplotlib命令与格式:删除,移动,修改axes脊柱(边框)
2017-12-07 00:07
525 查看
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 np import matplotlib.pyplot as plt fig, 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('--')
相关文章推荐
- matplotlib命令与格式:设置栅格,axes脊柱(坐标轴),背景颜色
- matplotlib命令与格式:图像(figure)与子区域(axes)布局与规划
- matplotlib命令与格式:图像(figure)与子区域(axes)布局与规划
- matplotlib命令与格式:设置折线与点属性
- matplotlib命令与格式:tick坐标轴日期格式(设置日期主副刻度)
- matplotlib命令与格式:tick坐标轴主副刻度设置
- matplotlib命令与格式:坐标轴数值格式(日期格式,百分比,科学记数)
- matplotlib命令与格式:参数配置文件与参数配置
- matplotlib命令与格式:图例legend语法及设置
- matplotlib命令与格式:系统字体与显示中文
- matplotlib命令与格式:axis坐标轴对象命令合集
- matplotlib命令与格式:标题(title),标注(annotate),文字说明(text)
- matplotlib命令与格式:tick刻度对象命令合集
- matplotlib 的 subplot, axes and axis
- python中引用matplotlib画图的几个常用命令及基本步骤
- 在python命令中,安装numpy,matplotlib等插件的方法
- matplotlib Axes.scatter 函数学习笔记
- matplotlib : axes.scatter
- matplotlib.axes.Axes.plot
- matplotlib去掉边框