简体   繁体   English

使用循环更改绘图中的颜色

[英]Changing colors in plot with loop

I know this question was asked a dozen times but I need help in my specific example. 我知道这个问题被问过十几遍,但是在我的具体例子中我需要帮助。 I just don't know why it's not working. 我只是不知道为什么它不起作用。

In the end i want 150 different lines but for now I just want to test it with 10 lines. 最后,我想要150条不同的线,但现在我只想用10条线对其进行测试。

The aim is to iterate through the colour map and my code looks like this: 目的是遍历颜色图,我的代码如下所示:

import matplotlib.pyplot as plt

jet= plt.get_cmap('jet')
colors = iter(jet(np.linspace(0,1,10)))
for k in range(0,10):
    plt.plot(u_ordered[0*k:42*(k+1)], T_ordered[0*k:42*(k+1)], 'o',
color=next(colors))


plt.xscale('log')
plt.ylabel('T [K]')
plt.xlabel('log u [KJ/g]')
plt.title('T - U (at const. Rho) Plot')
plt.legend(loc="lower right")
plt.savefig('T_u_const_rho_Plot1.pdf')
plt.show()

I keep on getting this for all the 150 lines: 我继续在所有150行中使用: 在此处输入图片说明

In each iteration of your loop, you are plotting over everything that you have already plotted. 在循环的每次迭代中,您都在绘制已经绘制的所有内容。 Try replacing the plotting part with 尝试将绘图部分替换为

plt.plot(u_ordered[42*k:42*(k+1)], T_ordered[42*k:42*(k+1)], 'o', color=next(colors))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM