Matplotlib条形图不绘制边框/边缘 [英] Matplotlib bar graph not drawing borders/edges

查看:1512
本文介绍了Matplotlib条形图不绘制边框/边缘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的条形图有此代码.

ax1 = plt.subplot2grid((1,1),(0,0))
ax1.bar(edges2, Nnorm, width=0.02, edgecolor='green', linewidth=20)

我认为这应该使我的条形图具有绿色边缘.但事实并非如此.它在最左边的绿色上形成一个小节.我究竟做错了什么? Facecolor有效.

I thought that should make my bar graph have green edges. But it does not. It makes one bar on the far left green. What am I doing wrong? Facecolor works.

推荐答案

不幸的是,这是一个matplotlib 2.1中的错误.它在matplotlib 2.2版中已修复.

Unfortunately, this is a bug in matplotlib 2.1. It is fixed in matplotlib version 2.2.

到目前为止,一种解决方法是分别设置每个条的边缘颜色和线宽:

As of now a workaround is to set the edgecolor and linewidth for each bar individually:

import matplotlib.pyplot as plt

bars = plt.bar(range(4), [3,4,1,5])
for bar in bars:
    bar.set_edgecolor("green")
    bar.set_linewidth(20)

plt.show()

这篇关于Matplotlib条形图不绘制边框/边缘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆