我希望能够使用matplotlib将线条的颜色更改为我在绘图上指定的颜色。
下面是我正在使用的相关代码(它是函数的一部分)。该变量avg_rel_track
是一个“ 2D数组”,每列对应一个“刀片”。每个“刀片”都画一条单独的线。
我希望每条刀片/线都是我指定的颜色。我正在努力寻找相关的文档,如果很明显,我感到很抱歉。
def plot_data(avg_rel_track, sd_rel_track_sum, shade):
fig = plt.figure(figsize=(18,10))
gs = gridspec.GridSpec(5, 1, height_ratios=[1.75, 1 ,1, 1])
ax0 = plt.subplot(gs[0])
ax1 = plt.subplot(gs[1])
ax2 = plt.subplot(gs[2])
ax3 = plt.subplot(gs[3])
ax4 = plt.subplot(gs[4])
fig.subplots_adjust(top=0.93)
#The following plot has 5 plots within it.
lineObjects = ax0.plot(avg_rel_track_nan)
ax0.set_title('Averaged Relative Track',fontsize=11)
ax0.legend(lineObjects, (1,2,3,4,5),loc='lower center', bbox_to_anchor=(0.82, 1),
fancybox=True, shadow=True, ncol=5)
以下是情节的示例(非常粗糙),我想将情节更改为我指定的情节。它是5个子图中的一个
问题在于该plot
函数仅接受一种颜色作为参数。因此,您必须遍历各列并分别绘制每一列。
columns = [[1,2,3],[1,4,5],[6,4,2]]
colors = ['green', 'pink', 'blue']
labels = ['foo', 'bar', 'baz']
fig, ax = plt.subplots(1, 1)
for i, column in enumerate(columns):
ax.plot(column, color=colors[i], label=labels[i])
ax.legend(loc='lower center', bbox_to_anchor=(0.82, 1),
fancybox=True, shadow=True, ncol=3)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句