python - 使用 matplotlib 线图的颜色图

标签 python matplotlib plot colormap

我想使用反向光谱颜色图

https://matplotlib.org/examples/color/colormaps_reference.html

用于线图。

这对于十六进制图来说效果很好::

color_map = plt.cm.Spectral_r
image = plt.hexbin(x,y,cmap=color_map)

但是当我这样做的时候

ax1.plot(x,y, cmp=color_map)

这给了我::

AttributeError: Unknown property cmap

注意,我只想设置 colormap 并让 matplotliob 完成剩下的工作;即我不想在 .plot 命令中使用 color=' argument

最佳答案

您可以看看这个解决方案 - 第三个变体就是您想要的:

https://stackoverflow.com/a/57227821/5972778

您需要提前知道要绘制多少条线,否则它不知道如何从范围中选择颜色。

关于python - 使用 matplotlib 线图的颜色图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46296422/

相关文章:

python - 如何多次迭代 ResultProxy?

python - numpy 数组梯度和 matplotlib quiver 的倒序

matlab - 整个循环完成后,在循环中绘制并保存绘图

r - 使用树状图和样本标签绘制热图

Python:提取特定范围内的数字数据

python - ipywidgets 使用复选框来显示或隐藏其他小部件

python - 图形执行中不允许使用 `tf.Tensor` 作为 Python `bool`。使用 Eager execution 或使用 @tf.function 装饰此函数

python matplotlib条形图添加条形标题

python - 如何使用 matplotlib 中的直方图输出绘制散点图?

r - 添加误差线以在R中的图上显示标准偏差