Set matplotlib shape size using 3d sub-patches

I have a figure where I want to build a 3D scatter and a normal plot in 2 subheadings. I am using this code

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

then I use ax and ax2 to build my data in the right place. But the number I get is too small, how can I make it bigger ?, adding figsize=(w, h)to the first line has no effect and leads to an error if I add it to the second or third line .:

AttributeError: the "Axes3DSubplot" object does not have the "set_figsize" attribute

+4
source share
1 answer

Adding figsize=(w,h)to the first line should do the trick. What do you mean by "it has no effect"?

For instance:

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)

png 300dpi:

$ 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
+3

Source: https://habr.com/ru/post/1599051/


All Articles