【问题标题】:Scatter Problem : ValueError: 'c' argument has 2 elements, which is inconsistent with 'x' and 'y' with size 70120分散问题:ValueError:'c' 参数有 2 个元素,与大小为 70120 的 'x' 和 'y' 不一致
【发布时间】:2023-03-03 21:06:01
【问题描述】:

我希望你一切都好。我正在 python 中使用 matplotlib 制作散点图,并希望 X 和 Y 轴的散点具有不同的颜色。我给它一个数组,但由于某种原因它给出了错误。

分散问题:ValueError: 'c' 参数有 2 个元素,即 与大小为 70120 的“x”和“y”不一致

这是我的代码

import matplotlib.pyplot as plt
import pandas as pd

#Reading The Data
soc_data = pd.read_csv('research/featurespace/optical_sar.csv')
print(soc_data.columns)

# Axis Data
x = soc_data.SOCOptical
y = soc_data.SOCSAR

#plotting
plt.scatter(x,y,s=0.001,color=['green','yellow'])
plt.title('2D Feature Space - SOC Optical v/s SOC SAR')
plt.xlabel('Optical Predicted SOC')
plt.ylabel('SAR Predicted SOC')
plt.show()

当我删除颜色属性时,这个图表就会显示出来。

enter image description here

请帮助我。

【问题讨论】:

标签: python matplotlib data-analysis scatter-plot


【解决方案1】:

当然,参数“color”必须与X和Y的大小相匹配。

这里的解决方案是给参数“color”一个字符串列表,指明每个点必须关联哪种颜色。

所以你需要给出一个包含 70120 个字符串的列表。

【讨论】:

    猜你喜欢
    • 2020-07-19
    • 2021-12-14
    • 2019-11-28
    • 1970-01-01
    • 1970-01-01
    • 2020-02-23
    • 2017-05-30
    • 2021-02-07
    • 1970-01-01
    相关资源
    最近更新 更多