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

标签 python matplotlib

我正在尝试在 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/

相关文章:

python - 如何抓取优惠券网站的优惠券代码(点击按钮即可获得优惠券代码)

python - 从 `matplotlib.pyplot.plot`获取点坐标

Python - Matplotlib 使用 pandas 数据框时绘制不正确的图形

python - 继承自matplotlib

python - 如果列位于列表的任何部分,则过滤数据框

python - 将数组拆分为预测矩阵和响应向量

python - 使用 Tensorflow 读取 PNG 文件

python - 将用户输入传递给节日

python - Matplotlib 标记子图

python - 每小时直方图 - matplotlib