python - 更改 python matplotlib python 图的配色方案

标签 python colors matplotlib plot color-mapping

<分区>

我想为我的 python 图设置一个配色方案,这样它们就不会像下面所示的顶部图中的 A 和 H 那样重复相同的颜色。 (对不起,如果它很难看)。 enter image description here

我使用的代码很简单,

ax1.plot(sections,A,label='A',linewidth=2) ax1.plot(sections,B,label='B',linewidth=2) ax1.plot(sections,C,label='C',linewidth=2) ax1.plot(sections,D,label='D',linewidth=2) ax1.plot(sections,E,label='E',linewidth=2) ax1.plot(sections,F,label='F',linewidth=2) ax1.plot(sections,G,label='G',linewidth=2) ax1.plot(sections,H,label='H',linewidth=2)

设置配色方案的最佳方式是什么?正在使用 colourmap 功能吗?感谢您的帮助!

最佳答案

您可以使用一些颜色图为线条着色,例如(这里我使用“jet”颜色图):

>>> from matplotlib import cm
>>> for i, val in enumerate(cm.jet(linspace(0,1,10))): #different lines
    plt.plot(arange(10), arange(10)+i, color=val, linestyle='-')

enter image description here

要在现有代码中以最少的更改执行此操作,只需添加(并且不要忘记将 10 更改为您拥有的地 block 数量。):

for L, C in zip([item for item in ax.get_children() if isinstance(item, matplotlib.lines.Line2D)], cm.jet(linspace(0,1,10))):
    L.set_color(C)   

关于python - 更改 python matplotlib python 图的配色方案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20021145/

相关文章:

python - AmazonS3 - 根据特定权限与 Python Boto 连接

python - 单击图表时显示的勾选标签?

java - 在 ACM 图形 API 中对颜色使用十六进制代码

algorithm - Mysql 确定最接近颜色匹配的算法

colors - 修改 Inno Setup 安装程序的配色方案

python - 我可以让 matplotlib slider 更离散吗?

python - Python 中具有正值和负值的堆积面积图

python - 在python中迭代和匹配大文件

python - 递归计算表达式python

python - 将 Python 环境移至新的操作系统安装