Matplotlib:曲线重叠时如何防止透明颜色重叠? [英] Matplotlib: How to prevent transparent color overlay when curve overlaps?
问题描述
例如,我们在此处绘制具有透明颜色的线
For example we plot a line with transparent color here
import numpy as np
import matplotlib.pyplot as plt
a = np.array([1, 2, 3, 4, 5])
b = 2*a
plt.plot(a, b, 'blue', alpha=0.3)
plt.show()
但是我要绘制同一条线多次,这些线会与自身重叠,因此与自身重叠的次数越多,其颜色就越深.
but wenn I plot the same line multiple times, that overlaps with itself, so that the more it overlaps with itself, the darker it becomes.
import numpy as np
import matplotlib.pyplot as plt
a = np.array([1, 2, 3, 4, 5])
b = 2*a
for i in range(3):
plt.plot(a, b, 'blue', alpha=0.3)
plt.show()
那么如何防止颜色重叠?
so How can I prevent the color-overlaps?
谢谢大家!
更新:我为什么需要这个?
我正在做公差分析.这意味着,参数会在samll范围内自行更改,我将为每次更改绘制曲线.然后我可以找到最坏的情况.
I am doing a Tolerance-Analysis. That means, the parameter change themselfs within a samll range and I will plot the curve for each change. Then I can find the worst case.
如果我选择纯色但较浅的颜色.它看起来像:
If I pick a solid but lighter color. It will looks like:
如您所见,颜色不透明,我无法观察到被其他行覆盖的节点.
As you can see, with untransparent color I can not observe the node, which is covered by other line.
更新2:
推荐答案
单行本身不会重叠.因此,您可以将多个图连接成一个图.
A single line does not overlay itself. Hence you can concatenate the multiple plots into a single one.
import numpy as np
import matplotlib.pyplot as plt
a = np.array([1, 2, 3, 4, 5])
b = 2*a
A = np.tile(np.append(a,[np.nan]),3)
B = np.tile(np.append(b,[np.nan]),3)
plt.plot(A, B, 'blue', alpha=0.3)
plt.show()
This is essentially the inverse of this question How can I draw transparent lines where the color becomes stronger when they overlap?, where this effect was undesired.
这篇关于Matplotlib:曲线重叠时如何防止透明颜色重叠?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!