gpt4 book ai didi

python - 使用 matplotlib 线图的颜色图

转载 作者:行者123 更新时间:2023-11-30 22:29:37 25 4
gpt4 key购买 nike

我想使用反向光谱颜色图

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com