美文网首页R/Python
「绘图」plt.subplots

「绘图」plt.subplots

作者: 茶苯海 | 来源:发表于2019-11-10 18:49 被阅读0次

基本使用

# First create some toy data 数据准备
x = np.linspace(0, 2*np.pi, 400)
y = np.sin(x**2)

# 一个图
# Creates just a figure and only one subplot
fig, ax = plt.subplots()
ax.plot(x, y)
ax.set_title('Simple plot')

# 创建两个subplots,直接打包ax  (ax1,ax2)
# Creates two subplots and unpacks the output array immediately
f, (ax1, ax2) = plt.subplots(1, 2, sharey=True)
ax1.plot(x, y)
ax1.set_title('Sharing Y axis')
ax2.scatter(x, y)

# 创建4个坐标,并通过返回数组调用
# Creates four polar axes, and accesses them through the returned array
fig, axes = plt.subplots(2, 2, subplot_kw=dict(polar=True))
axes[0, 0].plot(x, y)
axes[1, 1].scatter(x, y)

image.png

其他

# Share a X axis with each column of subplots
plt.subplots(2, 2, sharex='col')
# Share a Y axis with each row of subplots
plt.subplots(2, 2, sharey='row')
# Share both X and Y axes with all subplots
plt.subplots(2, 2, sharex='all', sharey='all')
# Note that this is the same as
plt.subplots(2, 2, sharex=True, sharey=True)
# Creates figure number 10 with a single subplot
# and clears it if it already exists.
fig, ax=plt.subplots(num=10, clear=True)

相关文章

网友评论

    本文标题:「绘图」plt.subplots

    本文链接:https://www.haomeiwen.com/subject/nrvabctx.html