【matplotlib】坐标轴等其他的设置解析(三)

相关作图文章:

第一篇:数据可视化之六大图
第二篇:更高级的绘图方式

一、坐标轴的设置

参考博文

  1. 《坐标轴刻度及范围设置》
  2. 《设置坐标轴刻度(主、次刻度)》

1.1 坐标轴的文本

ax.set_xlabel("x") 或者 ax.set_ylabel("y") ,用法相同

  • 含义
set_xlabel(xlabel, fontdict=None, labelpad=None, **kwargs) 
xlabel: 字符串,x轴的标签名
fontdict:字典,标签的属性
labelpad:标量,标签和x轴之间的点间距
  • 栗子
fig, ax =plt.subplots(figsize=(8, 5), dpi=80) 
x = np.arange(10) 
y = np.sin(x)  
ax.plot(y,label=r"$sin x$", color="C0")
font = {'family' : 'Times New Roman',
        'weight' : 'normal',
        'size'   : 18,
        'color':'red'}
ax.set_xlabel("x",fontdict=font,labelpad=1)
ax.set_ylabel("y")  

在这里插入图片描述

1.2 坐标轴的取值范围

ax.set_xlim()ax.set_ylim()

  • 含义
set_xlim(left=None, right=None, emit=True, auto=False, **kw)
left:标量,x轴左侧界限
right:标量,x轴右侧界限
emit:布尔值,是否将限额变更通知观察员
auto:布尔值,是否启用x轴的自动缩放。True开启
xlimits :元组,左xlim和右xlim可以作为元组(`left`、`right`)作为第一个位置参数(或者作为`left`关键字参数)传递。
  • 栗子
x = np.arange(10) 
y = np.sin(x)  
fig, (ax1,ax2) =plt.subplots(1,2,figsize=(16, 5), dpi=80) 
### 
ax1.plot(y,label=r"$sin x$", color="C0")
font = {'family' : 'Times New Roman',
        'weight' : 'normal',
        'size'   : 18,
        'color':'red'}
ax1.set_xlabel("x",fontdict=font,labelpad=1)
ax1.set_ylabel("y") 
ax1.set_title("befor set xlim of the same fun")

ax2.plot(y,label=r"$sin x$", color="C0")
ax2.set_xlabel("x",fontdict=font,labelpad=1)
ax2.set_ylabel("y") 
ax2.set_xlim(0,2)
ax2.set_title("after set xlim of the same fun")

在这里插入图片描述

设置背景颜色

set_backgroundcolor(self, color)

画一个边界框

set_bbox(self, rectprops)

设置艺术家的剪辑

set_clip_box(self, clipbox)

设置艺术家是否使用剪辑。

set_clip_on(self, b)

设置艺术家的剪辑路径,该路径可能是

set_clip_path(self, path, transform=None)

设置文本的前景色

set_color(self, color)

设置字体系列。

set_family(self, fontname)

设置字体属性

`set_font_properties(self, fp)``

set_fontsize(self, fontsize)

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值