【发布时间】:2021-04-15 17:41:03
【问题描述】:
我正在尝试使用 x 和 y 网格创建散点图,其中每个点都通过预先分配的值获得颜色:
{x: 1, y: 2, value: n}
我有一个 x 和 y 列表以及另一个值列表,尝试使用这个:
# make range of x(0 - 359) and y(-90 - 90)
x, y = np.meshgrid(range(0, 360), range(-90, 90))
colors = [a very long list (64800 values, one for each point)]
print(colors)
plt.scatter(x, y, c=colors)
plt.colorbar()
plt.show()
错误:
Traceback (most recent call last): File "C:\python3.6.6\lib\site-packages\matplotlib\colors.py", line 158, in to_rgba rgba = _colors_full_map.cache[c, alpha] KeyError: (1.0986122886681098, None) During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:\python3.6.6\lib\site-packages\matplotlib\axes\_axes.py", line 4210, in scatter colors = mcolors.to_rgba_array(c) File "C:\python3.6.6\lib\site-packages\matplotlib\colors.py", line 259, in to_rgba_array result[i] = to_rgba(cc, alpha) File "C:\python3.6.6\lib\site-packages\matplotlib\colors.py", line 160, in to_rgba rgba = _to_rgba_no_colorcycle(c, alpha) File "C:\python3.6.6\lib\site-packages\matplotlib\colors.py", line 211, in _to_rgba_no_colorcycle raise ValueError("Invalid RGBA argument: {!r}".format(orig_c)) ValueError: Invalid RGBA argument: 1.0986122886681098 During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:/Users/amit neumark/Documents/עמית/alpha/grbs data/grbs/find_burst_location.py", line 168, in <module> main() File "C:/Users/amit neumark/Documents/עמית/alpha/grbs data/grbs/find_burst_location.py", line 161, in main ra2, dec2 = chi_square(model, relations) File "C:/Users/amit neumark/Documents/עמית/alpha/grbs data/grbs/find_burst_location.py", line 33, in chi_square create_plot(sums) File "C:/Users/amit neumark/Documents/עמית/alpha/grbs data/grbs/find_burst_location.py", line 134, in create_plot plt.scatter(x, y, c=colors) File "C:\python3.6.6\lib\site-packages\matplotlib\pyplot.py", line 2793, in scatter verts=verts, edgecolors=edgecolors, data=data, **kwargs) File "C:\python3.6.6\lib\site-packages\matplotlib\__init__.py", line 1785, in inner return func(ax, *args, **kwargs) File "C:\python3.6.6\lib\site-packages\matplotlib\axes\_axes.py", line 4223, in scatter .format(nc=n_elem, xs=x.size, ys=y.size) ValueError: 'c' argument has 64800 elements, which is not acceptable for use with 'x' with size 64800, 'y' with size 64800.
【问题讨论】:
-
我们需要知道颜色列表中的值。
标签: python matplotlib scatter-plot