gpt4 book ai didi

python - 在 matplotlib 条形图中显示非常窄的矩形的颜色

转载 作者:行者123 更新时间:2023-12-01 04:24:46 25 4
gpt4 key购买 nike

我正在尝试在 matplotlib 中绘制 x 轴范围非常宽的数据。我有两组数据,我希望通过两种颜色来区分。但是,标准条形图中使用的矩形太窄,以至于无法显示颜色。这是我正在使用的代码:

import matplotlib.pyplot as plt
fig=plt.figure()
ax1=fig.add_subplot(111)
ax1.bar(plotreal,plotabundance,color='#330000') #first data (x,y,color)
ax1.bar(xlist,ylist,color='#9999FF') #second set of data (x,y,color)
ax1.set_xlabel() #some axis labeling
ax1.set_ylabel() #some axis labeling
ax1.set_title() #some title labeling
plt.savefig('chart of '+str(counter)+'.png') #some more parameters

第二组中的数据可能与第一组数据重叠(具有相同的点),我希望在这种情况下显示其颜色。我有兴趣保持这种显示格式,其中每个点显示为线条/矩形,只需向线条/矩形添加颜色。

尽管我尝试对两个数据集设置对比色,但仍然无法区分此示例中的第二组仅包含 4 个坐标,而第一组包含其余的坐标。

sample data

(如果有人好奇的话,这是质谱仪的输出数据)

是否还缺少其他图形类型或参数可以用来解决此颜色问题?提前致谢。

最佳答案

边缘颜色由不同的参数设置(默认=黑色)。您的条形图太小,看不到填充颜色,因此它看起来是黑色的,因为边缘保持相同的大小!

要修复,添加edgecolor=...:

import matplotlib.pyplot as plt
fig=plt.figure()
ax1=fig.add_subplot(111)
ax1.bar(plotreal,plotabundance,color='#330000',edgecolor='#330000') #first data (x,y,color,edgecolor)
ax1.bar(xlist,ylist,color='#9999FF',edgecolor='#9999FF') #second set of data (x,y,color,edgecolor)
ax1.set_xlabel() #some axis labeling
ax1.set_ylabel() #some axis labeling
ax1.set_title() #some title labeling
plt.savefig('chart of '+str(counter)+'.png') #some more parameters

关于python - 在 matplotlib 条形图中显示非常窄的矩形的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33286021/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com