Graph Not Showing Up When Using Google Colabratory 在使用Google Colabratory时,图表无法显示出来。

23 浏览
0 Comments

Graph Not Showing Up When Using Google Colabratory 在使用Google Colabratory时,图表无法显示出来。

我正在尝试使用numpy和matplotlib.pyplot在Google Colabratory中绘制一个剪力图,但是它在输出部分没有显示出来。我的代码如下:\n

import matplotlib.pyplot as plt
import numpy as np
# 创建图表
x = np.linspace(0, d_OA + d_AB + d_BC, 1000)
V_xy = np.zeros_like(x)
for idx, loc in enumerate(x):
    if loc < d_OA:
        V_xy[idx] = R_oy
    elif ((loc >= d_OA) and (loc < d_OA + d_AB)):
        V_xy[idx] = R_oy - T_A*np.sin(theta_A)
    elif ((loc >= d_OA + d_AB) and (loc < d_OA + d_AB + d_BC)):
        V_xy[idx] = R_oy - T_A*np.sin(theta_A) - W*np.sin(theta_B)
    else:
        V_xy[idx] = R_oy - T_A*np.sin(theta_A) - W*np.sin(theta_B) + R_cy
    V_xy[0] = 0
# 绘制图表
plt.plot(x, V_xy, '-')
plt.grid(True)
plt.xlabel('x / m')
plt.ylabel('Vxy / N')

\n如果有人能帮忙,我会非常感激。

0
0 Comments

问题的原因是在导入matplotlib.pyplot库之后,没有添加%matplotlib inline。

解决方法是在导入matplotlib.pyplot库之后添加%matplotlib inline。

以下是代码示例:

import matplotlib.pyplot as plt
%matplotlib inline

通过添加%matplotlib inline,可以确保在Google Colabratory中正确显示图形。

0