python-3.x - ValueError:RGBA 参数无效(数组形状不正确)
问题描述
我查看了有关此错误的其他线程,但找不到解决我的问题的方法。
我正在尝试将此存储库更新为 python 3,但我不断收到此错误。
/usr/local/lib/python3.7/dist-packages/matplotlib/colors.py in _to_rgba_no_colorcycle(c, alpha)
266 # float)` and `np.array(...).astype(float)` all convert "0.5" to 0.5.
267 # Test dimensionality to reject single floats.
--> 268 raise ValueError(f"Invalid RGBA argument: {orig_c!r}")
269 # Return a tuple to prevent the cached value from being modified.
270 c = tuple(c.astype(float))
ValueError: Invalid RGBA argument: [(array([0.5, 0. , 1. , 1. ]),), (array([0.50392157, 0.99998103, 0.70492555, 1. ]),), (array([1.0000000e+00, 1.2246468e-16, 6.1232340e-17, 1.0000000e+00]),)]
这是我修改的代码。
def timeit_plot2D(data, xlabel='xlabel', title='title', **kwargs):
"""Plots the results from a defaultdict returned by timeit_compare.
Each function will be plotted as a different series.
timeit_compare may test many conditions, and the order of the conditions
in the results data can be understood from the string substitutions
noted in the keys of the defaultdict. By default series=0 means
that the first series is plotted, but this can be changed to plot
any of the testing conditions available.
"""
series = kwargs.get('series', 0)
style = kwargs.get('style', 'line')
size = kwargs.get('size', 500)
ylabel = kwargs.get('ylabel', 'time')
cmap = kwargs.get('cmap', 'rainbow')
lloc = kwargs.get('lloc', 2)
dataT = {}
# set color scheme
c = iter(plt.get_cmap(cmap)(np.linspace(0, 1, len(data))))
# transpose the data from [x, y, z]... into ([x...], [y...], [z...])
for k, v in data.items():
dataT[k] = list(zip(*v))
fig, ax = plt.subplots()
for k, v in dataT.items():
if style == 'scatter':
ax.scatter(v[series], v[-1], s=size, c=next(c), alpha=.75)
elif style == 'bubble':
x, y, z = v[series[0]], v[series[1]], v[-1]
ax.scatter(x, y, s=[size*i for i in z], c=next(c), alpha=.5)
else:
ax.plot(v[series], v[-1], c=list(zip(c)), lw=2)
# TODO: BUG: no way to set other parameters manually (README fig2)
ax.legend([substitute_titles(k,series) for k in dataT.keys()], loc=lloc)
ax.set_xlabel(xlabel)
ax.set_ylabel(ylabel)
ax.set_title(title)
ax.grid(True)
return fig
我相信问题出在这条线上。
c = iter(plt.get_cmap(cmap)(np.linspace(0, 1, len(data))))
但是,我一直无法将其转换为有意义的东西。
非常感谢任何帮助。
解决方案
推荐阅读
- python-3.x - 在模块内运行的模块返回 - 类型错误:“numpy.float64”对象不能解释为整数
- apache-spark - 在纱线上使用 python 3.x 运行 spark 2.3
- java - Java - 12 小时到 24 小时格式 (hackerrank)
- linux - 在 Docker 容器下挂载 CIFS 不会影响主机挂载的卷
- java - 不能递归地对矩阵中的所有偶数求和
- python - 使用类型注释记录类属性
- azure-functions - 针对 Cosmos Db DocumentClient 的 Azure Function V2
- javascript - CSRF 到 getcitydetails jquery 函数
- vim - Vim vs 命令在第二个窗格中创建重复输出
- angular - Angular Http Get 404 停止进一步调用