【发布时间】:2021-07-15 05:11:46
【问题描述】:
我目前在为我的错误栏设置颜色范围方面遇到了一些麻烦。显然,看起来有两个错误栏相互强加。一种是橙色,另一种是红色。作为参考,我按照这篇文章中的步骤操作:Setting Different error bar colors in bar plot in matplotlib 并进行了调整以适应。有没有办法解决这个小问题?
我还将包括.csv file for usage。目前,代码运行如下:
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()
【问题讨论】:
标签: python matplotlib