首页 > 解决方案 > 使用 Google Colaboratory 时图表不显示

问题描述

我正在尝试使用 numpy 和 matplotlib.pyplot 在 Google Colabratory 中绘制剪切力图,但它没有出现在输出部分。我的代码如下:

import matplotlib.pyplot as plt
import numpy as np

# Create the graphu
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

# Plot the graph
plt.plot(x, V_xy, '-')
plt.grid(True)
plt.xlabel('x / m')
plt.ylabel('Vxy / N')

如果有人可以提供帮助,我将不胜感激。

标签: pythonnumpymatplotlibgraphjupyter

解决方案


我发现了问题!我没跑%matplotlib inline就跑import matplotlib.pyplot as plt


推荐阅读