【问题标题】:Matplotlib scatter plot with unknown error未知错误的 Matplotlib 散点图
【发布时间】:2016-06-14 11:30:45
【问题描述】:

我正在尝试创建散点图。我有一个从 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()

【问题讨论】:

    标签: python numpy matplotlib


    【解决方案1】:

    检查scatter documentation。第三个参数是点的大小,应该是标量或类似数组的。我假设'r' 用于颜色,所以请执行以下操作:

    plt.scatter(x, y, c='r')
    

    【讨论】:

    • 谢谢你,这很有意义。我正在阅读它,但省略了 c= 部分,因为它在正常绘图中是不必要的。两种样式之间有不同的语法似乎很愚蠢。
    猜你喜欢
    • 1970-01-01
    • 2021-04-15
    • 2020-08-27
    • 1970-01-01
    • 2018-10-24
    • 2018-05-17
    • 2020-07-22
    相关资源
    最近更新 更多