【问题标题】:Set size of matplotlib figure with 3d subplots使用 3d 子图设置 matplotlib 图形的大小
【发布时间】:2015-07-22 09:33:00
【问题描述】:

我有一个图,我想在 2 个子图中绘制一个 3d 散点图和一个正常图。 我用这个代码

fig = plt.figure(1)
ax = fig.add_subplot(211, projection='3d')
ax2 = fig.add_subplot(212)

然后我使用 ax 和 ax2 将我的数据绘制在正确的位置。但是我得到的图太小了,怎么把它变大呢,第一行加figsize=(w, h)没有任何作用,加到第二行或者第三行会报错:

AttributeError: 'Axes3DSubplot' 对象没有属性 'set_figsize'

【问题讨论】:

标签: python matplotlib


【解决方案1】:

figsize=(w,h) 添加到第一行应该可以解决问题。 “没有效果”是什么意思?

例如:

import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

fig1=plt.figure(figsize=(8,5))
ax11=fig1.add_subplot(211,projection='3d')
ax12=fig1.add_subplot(212)

fig1.get_size_inches()
# array([ 8.,  5.])

fig2=plt.figure(figsize=(4,4))
ax21=fig1.add_subplot(211,projection='3d')
ax22=fig1.add_subplot(212)

fig2.get_size_inches()
# array([ 4.,  4.])

fig1.savefig('fig1.png',dpi=300)
fig2.savefig('fig2.png',dpi=300)

将图形保存为 300dpi 的 png 格式后:

$ identify fig1.png
>>> fig1.png PNG 2400x1500 2400x1500+0+0 8-bit sRGB 118KB 0.000u 0:00.000

$ identify fig2.png
>>> fig2.png PNG 1200x1200 1200x1200+0+0 8-bit sRGB 86.9KB 0.000u 0:00.000

【讨论】:

    猜你喜欢
    • 2017-12-12
    • 2021-11-24
    • 2017-05-22
    • 2022-10-13
    • 2019-04-30
    • 1970-01-01
    • 1970-01-01
    • 2015-04-01
    • 1970-01-01
    相关资源
    最近更新 更多