Bog*_*ski 28 python numpy matplotlib
我试图创建一个散点图.我有一个0到17的数字列表以及一个包含18个值的数组.我可以将数据绘制为线图,但当我尝试绘制为散点图时,我收到一条错误消息,我不明白:TypeError: ufunc 'sqrt' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''
此错误消息的含义是什么?如何将数据绘制为散点图?
import numpy as np
import matplotlib.pyplot as plt
y = [7316.0, 7453.25, 7518.25, 7711.5, 7448.0, 7210.25, 7416.75, 6960.75,
7397.75, 6397.5, 5522.75, 5139.0, 5034.75, 4264.75, 5106.0, 3489.5,
4712.0, 4770.0]
x = np.arange(0,18,1)
plt.rcParams['legend.loc'] = 'best'
plt.figure(1)
plt.xlim(0, 20)
plt.ylim(0, 10000)
plt.scatter(x, y, 'r')
plt.show()
Run Code Online (Sandbox Code Playgroud)
gsm*_*fra 57
检查分散文档.第三个参数是针对点的大小,应该是标量或array_like.我假设'r'是为了颜色,所以做以下事情:
plt.scatter(x, y, c='r')
Run Code Online (Sandbox Code Playgroud)