是否可以仅更改误差线的透明度?使用plt.errorbar()更改的Alpha值会同时影响标记和误差线。
编辑:
就我而言,我有几个不同的数据集,每个值都有其自己的误差,因此我使用来绘制每个数据集plt.errorbar()。这是使用3个不同数据集的MWE:
import matplotlib.pyplot as plt
import numpy as np
x1 = [np.random.uniform(0,10,5)]
x2 = [np.random.uniform(0,10,5)]
x3 = [np.random.uniform(0,10,5)]
y1 = [np.random.uniform(0,10,5)]
y2 = [np.random.uniform(0,10,5)]
y3 = [np.random.uniform(0,10,5)]
err1 = [np.random.uniform(1,2, 5)]
err2 = [np.random.uniform(1,2, 5)]
err3 = [np.random.uniform(1,2, 5)]
plt.errorbar(x1, y1, xerr=err1, yerr=err1, fmt='ro', ms=10)
plt.errorbar(x2, y2, xerr=err2, yerr=err2, fmt='bs', ms=10)
plt.errorbar(x3, y3, xerr=err3, yerr=err3, fmt='g^', ms=10)
plt.show()
Run Code Online (Sandbox Code Playgroud) 在图例中设置透明度时:
plt.legend(framealpha=0.5)
Run Code Online (Sandbox Code Playgroud)
它同时影响背景和边缘。如何仅将透明度应用于背景而不应用于边缘?
我试过了:
plt.legend(edgecolor=(0, 0, 0, 1.), facecolor=(1, 1, 1, 0.1))
Run Code Online (Sandbox Code Playgroud)
使用它我可以更改颜色但不能更改透明度,即 usingfacecolor=(1, 0, 0, 0.1)确实将背景颜色更改为红色,但 usingfacecolor=(1, 0, 0, 0.5)不会对透明度产生任何影响。
我正在使用 matplotlib v3.1.1。
我正在尝试使该数据适合高斯
x = [4170.177259096838, 4170.377258006199, 4170.577256915561, 4170.777255824922, 4170.977254734283, 4171.177253643645, 4171.377252553006, 4171.577251462368, 4171.777250371729, 4171.977249281091, 4172.177248190453, 4172.377247099814, 4172.577246009175, 4172.777244918537, 4172.977243827898, 4173.17724273726, 4173.377241646621, 4173.577240555983, 4173.777239465344, 4173.977238374706, 4174.177237284067, 4174.377236193429, 4174.57723510279, 4174.777234012152, 4174.977232921513, 4175.177231830875, 4175.377230740236, 4175.577229649598, 4175.777228558959, 4175.977227468321, 4176.177226377682, 4176.377225287044, 4176.577224196405, 4176.777223105767, 4176.977222015128, 4177.17722092449, 4177.377219833851, 4177.577218743213, 4177.777217652574, 4177.977216561936, 4178.177215471297, 4178.377214380659, 4178.57721329002, 4178.777212199382, 4178.977211108743, 4179.177210018105, 4179.377208927466, 4179.577207836828, 4179.777206746189, 4179.977205655551, 4180.177204564912, 4180.377203474274, 4180.577202383635, 4180.777201292997, 4180.977200202357, 4181.17719911172, 4181.377198021081, 4181.577196930443, 4181.777195839804, 4181.977194749166, 4182.177193658527, 4182.377192567888, 4182.5771914772495, 4182.777190386612, 4182.9771892959725, 4183.177188205335, 4183.377187114696, 4183.577186024058, 4183.777184933419, 4183.9771838427805, 4184.177182752143, 4184.3771816615035, 4184.5771805708655, 4184.777179480228, 4184.977178389589, 4185.1771772989505, 4185.3771762083115, …Run Code Online (Sandbox Code Playgroud)