matplotlab库中的核心概念总结【Figure、Axes、subplot、Axis】容易混淆的概念

参考文档:https://www.zhihu.com/question/51745620

 

 

关于方法add_axes 和 add_subplot 创建axes画图区域的区别

 

import matplotlib.pyplot as plt
import pandas as pd
import numpy as np

x = np.random.randint(1, 10, 3)
y = np.arange(0, 3, 1)

# 创建一个画板的意思
fg = plt.figure()  # type:plt.Figure

# 在画板上添加一个可绘画的区域【坐标轴】
ax = fg.add_subplot(1, 1, 1)  # type:plt.Axes

# 接下来一系列操作都是基于axes对象中操作!
ax.locator_params(axis="x", nbins=2, tight=True)
a1, = ax.plot(y, x, "r.--", label="line", )
a2, = ax.plot(y + 1, "g.--", label="line2")
ax.legend((a1, a2), ("line", "line2"))
fg.show()

 

import matplotlib.pyplot as plt
import pandas as pd
import numpy as np

x = np.arange(1, 12, 4)
y = np.arange(1, 4, 1)

fg = plt.figure()  # type:plt.Figure
# 这里是[left, bottom, width, height] 是百分比小数【相对figure】
ax = fg.add_axes([0, 0, 1, 1])
ax1 = fg.add_axes([0.1, 0.1, 0.5, 0.5])

ax.plot(x, y)
ax1.plot(x, y)
fg.show()

 

 

 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值