python - Matplotlib:曲线重叠时如何防止透明颜色叠加?

标签 python matplotlib plot alpha alpha-transparency

例如,我们在这里绘制一条透明颜色的线

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()

enter image description here

但是我多次绘制同一条线,与自身重叠,因此与自身重叠越多,它变得越暗。
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()

enter image description here

那么如何防止颜色重叠?

谢谢大家!

更新:为什么我需要这个?

我正在做一个公差分析。这意味着,参数会在很小的范围内改变自己,我将绘制每次变化的曲线。然后我可以找到最坏的情况。

enter image description here

如果我选择纯色但较浅的颜色。它看起来像:

enter image description here

如您所见,使用不透明的颜色我无法观察被其他线覆盖的节点。

更新 2:

enter image description here

最佳答案

单行不会覆盖自身。因此,您可以将多个图连接成一个。

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()

enter image description here

这基本上是这个问题的反面 How can I draw transparent lines where the color becomes stronger when they overlap? ,这种效果是不希望的。

关于python - Matplotlib:曲线重叠时如何防止透明颜色叠加?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50930770/

相关文章:

python - 如何在 Windows 上 pip 或 easy_install tkinter

python - 如何以编程方式创建重复图像模式?

python - cx_Freeze 构建错误

python - 给定它的值,更改所选 matplotlib 直方图 bin 条的颜色

python - 使用字典绘制条形图并使用另一个字典为每个条形指定指定的颜色

r - 在 Shiny 的面板中绘制两个图形,一个图形在另一个图形下方

python - 简单的正则表达式来查找两个单词

python - 气泡图,气泡大小等于Python中的组大小

python Pandas : How I can determine the distribution of my dataset?

r - rplot_ly scatter中的自定义颜色范围