Python Re:为matplotlib中的错误栏设置不同的颜色

Python Re:为matplotlib中的错误栏设置不同的颜色,python,matplotlib,Python,Matplotlib,我目前在为我的错误栏设置颜色范围方面遇到了一些麻烦。显然,似乎有两个错误条相互施加。一个是橙色,另一个是红色。作为参考,我遵循了本文中的步骤:并进行了调整以适应。有没有办法解决这个小问题 我还将包括。目前,代码的运行方式如下: import matplotlib.pyplot as plt import numpy as np import pandas as pd from scipy.stats import linregress df = pd.read_csv('Regression.

我目前在为我的错误栏设置颜色范围方面遇到了一些麻烦。显然,似乎有两个错误条相互施加。一个是橙色,另一个是红色。作为参考,我遵循了本文中的步骤:并进行了调整以适应。有没有办法解决这个小问题

我还将包括。目前,代码的运行方式如下:

import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from scipy.stats import linregress

df = pd.read_csv('Regression.csv') 
df.head()

A = df['Period'] #Period in Days 
B = df['Luminosity'] #Luminosity is already Logarithmic prior to calculation
colors = ['red', 'orange', 'forestgreen', 'teal', 'navy', 'darkorchid'] #range of colors

#Luminosity Uncertainties
ylower_error = df['-dY lum'] #lower limit
yupper_error = df['+dY lum'] #upper limit
yasymmetric_error = [ylower_error, yupper_error]

#Regression space
slope, intercept, r_value, p_value, std_err = linregress(np.log10(A+1), np.array(B))

xfid = np.linspace(2,3)   # This is just a set of x to plot the straight line 

#Plotting the overall data
fig, ax = plt.subplots(figsize=(12, 10))

ax.scatter(np.log10(A), np.array(B), marker='*', s=300, color=colors)
ax.plot(xfid, xfid*slope+intercept,  '-.', c='royalblue', linewidth=3, zorder=0)
ax.set_xlim([2.46, 2.77]) #X-Limits
ax.set_ylim([4.35, 5.45]) #Y-Limits

#Setting the range of colors for the error bar. This one came from the reference post.
for yerr, color in zip(yasymmetric_error, colors):
    ax.errorbar(np.log10(A), np.array(B), yerr, lw=2, capsize=3, 
                capthick=2, ls='none', ecolor=color)

plt.rcParams['axes.linewidth'] = 4
plt.tight_layout()

循环应单独枚举组件。其思想是,每个错误条都是单独绘制的,因此在每次迭代中,您可以绘制
x
y
下部
上部
颜色的单个组合:

对于x、y、下、上、zip中的颜色(np.log10(A)、np.array(B)、ylower\u错误、yupper\u错误、颜色):
ax.errorbar(x,y,yerr=np.array([[下],[上]]),lw=2,倾覆=3,
capthick=2,ls='none',ecolor=color)