相当于在Python的Line2D中使用属性“ figsize”

问题描述 投票:0回答:1

我正在尝试绘制Line2D图并更改其大小以使其在Python中变大。我试图将功能更改为:

# Single 1D Discretized Brownian Motion
np.random.seed(5)
fig = plt.figure()

# Initialize the parameters        
T = 1
N = 501 # Number of points, number of subintervals = N-1
dt = T/(N-1) # Time step ()

# time units
t = np.linspace(0,T,N)

# Vectorized option (more efficient)  
dX = np.sqrt(dt) * np.random.randn(1,N)
X = np.cumsum(dX, axis=1)

plt.plot(t, X[0,:],figsize=(15,12))
plt.xlabel('$t$', fontsize=15)
plt.ylabel(' $X(t)$', fontsize=15)
plt.title('1D Discretized Brownian Path', fontsize=14)

plt.show()

感兴趣的行是导致错误的plt.plot(t, X[0,:],figsize=(15,12))

AttributeError: 'Line2D' object has no property 'figsize'

更改图形大小的另一种方法是什么?在这种情况下,如何增加其尺寸?如果有明显答案,我谨此致歉,我是Python新手。

python matplotlib plot figure
1个回答
0
投票

figsizematplotlib.figure.Figure s的属性。有多种设置方法(请参见matplotlib.figure.Figure),但在这种情况下最简单的方法可能是添加

this question

在调用plt.figure(figsize=(15,12)) 之前,即

plt.plot

这将创建一个具有指定大小的# ... plt.figure(figsize=(15,12)) plt.plot(t, X[0,:]) # ... 实例,并将该实例设置为“当前”图形-这就是Figure将使用的图形。

© www.soinside.com 2019 - 2024. All rights reserved.