2017-06-13 36 views
-1

このコードを変更して、軸のスケールを変更せずにプロットが大きくなるような簡単な方法はありますか?私はplt.gca().set_aspect('equal', adjustable='box')プロットを取り除く場合matplotlibサブプロットのサイズを変更する

enter image description here

import numpy as np 
import matplotlib.pyplot as plt 
import math 
%matplotlib inline 

a, c = -10, 10         
x = np.linspace(a,c,100)       
x = np.array(x) 
def y(x): return np.arctan(x)      

h = 0.0000001         

def grad(x,h): return (y(x+h)-y(x))/h   
m = grad(x,h) 

plt.figure(1) 
plt.subplot(121) 
plt.plot(x, y(x), 'b') 
plt.xlim([a,c]) 
plt.ylim([min(y(x)),max(y(x))]) 
plt.gca().set_aspect('equal', adjustable='box') 

plt.subplot(122) 
plt.plot(x,m,'b') 
plt.xlim([a,c]) 
plt.ylim([min(m),max(m)]) 
plt.gca().set_aspect('equal', adjustable='box') 

plt.subplots_adjust(wspace = 0.5) 
plt.show() 

はまともなサイズは出てくるが、彼らは縮尺通りではありません。

答えて

2

サブプロットは、アスペクトが同じになるように縮小されています。これは望ましいと思われる。したがって、「より大きい」が何を指しているかは本当に明確ではありません。

あなたはまだ数字を大きくすることができます。次いで

plt.figure(1, figsize=(12,2)) 

plt.subplots_adjustを用いて余白と間隔を調整します。 enter image description here

また、最後にお互いの下にサブプロットをプロットするだけでなく、それらが大きくなり

plt.gca().set_aspect('equal', adjustable='datalim') 

enter image description here

、軸はスケールしたデータのみに等しい側面を設定することができます。したがって、plt.subplot(211)plt.subplot(212)を使用することがあります。 enter image description here

関連する問題