【发布时间】:2018-06-23 13:00:39
【问题描述】:
我试图制作一个显示许多线条的情节,但很难将它们区分开来。它们有不同的颜色,但我想让它更容易显示哪条线是哪条线。一个普通的图例并不能很好地工作,因为我有超过 10 行。
这些行遵循逻辑顺序。我想(1)从颜色图中自动选择它们的颜色(最好是具有平滑顺序的颜色,例如绿色或彩虹)。然后我希望 (2) 在颜色条旁边有刻度线以对应于每行的索引i(或者更好的是来自字符串数组的文本标签textlabels[i])。
这是一段最少的代码(有一些空白,我不确定要使用什么)。我希望这能说明我正在尝试什么。
import numpy as np
import matplotlib.pyplot as plt
# Genereate some values to plot on the x-axis
x = np.linspace(0,1,1000)
# Some code to select a (discrete version of) a rainbow/viridis color map
...
# Loop over lines that should appear in the plot
for i in range(0,9):
# Plot something (using straight lines with different slope as example)
plt.plot(i*x)
# Some code to plot a discrete color bar next
# to the plot with ticks showing the value of i
...
我目前有这个。我希望彩条旁边有值为 i 的刻度,即 0、1、2、... 作为刻度线。
Example figure of what I have now. It is hard to tell the lines apart now.
【问题讨论】:
-
找到了一些部分提示through this link,其中讨论了如何控制线条颜色循环,但我还没有弄清楚如何解决我的全部问题。
标签: python matplotlib colors legend colorbar