Python中如何绘制这种图,或者用什么库可以实现

我昨天查了一下 Matplotlib 这个库 发现这个库有点太复杂了, 一时半会理解不了

有没有简单点的办法实现,求指点一下


Python中如何绘制这种图,或者用什么库可以实现
6 回复

看样子你是要实现一个进度条啊 可以看看这个
https://github.com/tqdm/tqdm


用Matplotlib配合Seaborn就能搞定,这种图通常是带误差线的柱状图或箱线图。

核心代码示例:

import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np

# 生成示例数据
categories = ['A', 'B', 'C', 'D']
values = np.random.randn(100, 4)  # 4组随机数据
means = values.mean(axis=0)
std_errors = values.std(axis=0) / np.sqrt(values.shape[0])

# 创建带误差线的柱状图
fig, ax = plt.subplots(figsize=(8, 6))
bars = ax.bar(categories, means, yerr=std_errors, capsize=5, 
              color='skyblue', edgecolor='black')

# 添加数值标签
for bar in bars:
    height = bar.get_height()
    ax.text(bar.get_x() + bar.get_width()/2, height + 0.01,
            f'{height:.2f}', ha='center', va='bottom')

ax.set_ylabel('测量值', fontsize=12)
ax.set_title('带误差线的柱状图示例', fontsize=14)
ax.grid(axis='y', alpha=0.3)
plt.tight_layout()
plt.show()

如果是要箱线图:

fig, ax = plt.subplots(figsize=(8, 6))
sns.boxplot(data=pd.DataFrame(values, columns=categories), ax=ax)
ax.set_ylabel('数值分布', fontsize=12)
ax.set_title('箱线图示例', fontsize=14)
plt.tight_layout()
plt.show()

用Matplotlib做基础绘图,Seaborn增强统计图表效果。

![pygal]( http://www.pygal.org/en/stable/documentation/types/bar.html)
pygal 这个库算简单的了,我当时比较了几种流行图标库选的它。bar stacked 水平方向,画一行,去掉表头,接近你的需求。

不是进度条 我想图表示使用量

感谢 我研究一下

我用 pil 实现了一下

from PIL import Image
imbg = Image.new(‘RGB’,(300,30),‘gray’)
imft = Image.new(‘RGB’,(30,30), ‘green’)
imbg.paste(imft)
imbg.save(r’d:\a.bmp’)

感谢各位大神

回到顶部