Matplotlib剑客行——容纳百川的艺术家教程

个性签名:整个建筑最重要的是地基,地基不稳,地动山摇。而学技术更要扎稳基础,关注我,带你稳扎每一板块邻域的基础。
博客主页:七归的博客
收录专栏:Python三剑客之江湖云
南来的北往的,走过路过千万别错过,错过本篇,“精彩”可能与您失之交臂yo
Triple attack(三连击):Comment,Like and Collect—>Attention

自定义您的对象

primitives(基本元素)
container(容器)

对象容器

Figure容器(图容器)
fig = plt.figure()
ax1 = fig.add_subplot(211)	# 作一幅2*1的图,选择第1个子图
ax2 = fig.add_axes([0.1, 0.1, 0.7, 0.3])	# 位置参数,四个数分别代表了(left,bottom,width,height)
ax1
print(fig.axes)		# fig.axes 中包含了subplot和axes两个实例

AxesSubplot:
[AxesSubplot:, <matplotlib.axes._axes.Axes object at 0x7f0768702be0>]

Matplotlib剑客行——容纳百川的艺术家教程

for ax in fig.axes:
    ax.grid(True)
import matplotlib.lines as lines

fig = plt.figure()
l1 = lines.Line2D([0, 1], [0, 1], transform=fig.transFigure, figure=fig)
l2 = lines.Line2D([0, 1], [1, 0], transform=fig.transFigure, figure=fig)
fig.lines.extend([l1, l2])
plt.show()
Axes容器(轴容器)
ax = fig.add_subplot()
rect = ax.patch  # 矩形实例
rect.set_facecolor('green')
Axis容器(轴容器)
# 设置刻度上的刻度格式
from matplotlib import ticker

formatter = ticker.FormatStrFormatter("自定义格式")
ax1.yaxis.set_major_formatter(formatter)
Tick容器(刻度容器)
import numpy as np
import matplotlib.pyplot as plt

# 固定随机状态以实现再现性
np.random.seed(19680801)

fig, ax = plt.subplots()
ax.plot(100*np.random.rand(20))
# 设置ticker的显示格式
ax.yaxis.set_major_formatter('${x:1.2f}')
# 设置ticker的参数,右侧为主轴,颜色为绿色
ax.yaxis.set_tick_params(which='major', labelcolor='green',
                         labelleft=False, labelright=True)

plt.show()

共计人评分,平均

到目前为止还没有投票!成为第一位评论此文章。

(0)
乘风的头像乘风管理团队
上一篇 2023年3月11日
下一篇 2023年3月11日

相关推荐