matplotlib pyton 如何画柱状图,利用kimi,直接把图拉倒上面,让他生成

要绘制类似于您提供的图像的柱状图,您可以使用Python中的Matplotlib库,这是一个非常流行的绘图库。以下是一个简单的示例代码,展示如何使用Matplotlib来创建一个类似的柱状图:

```python

import matplotlib.pyplot as plt

import numpy as np

数据

categories = ['中,火车', '中,测试', '强壮,训练', '强,测试']

stm_values = [1.07412, 1.12613, 0.94519, 0.93205]

bnn_values = [0.37709, 0.4424, 0.40883, 0.36503]

gan_values = [0.29486, 0.3558, 0.19483, 0.1721]

设置柱状图的位置

x = np.arange(len(categories))

width = 0.2

创建柱状图

fig, ax = plt.subplots()

rects1 = ax.bar(x - width, stm_values, width, label='双线性STM')

rects2 = ax.bar(x, bnn_values, width, label='BNN')

rects3 = ax.bar(x + width, gan_values, width, label='甘')

添加文本标签、标题和自定义x轴刻度标签

ax.set_ylabel('KL Divergence(nats)')

ax.set_title('三个基于DL的信道模型的输出数据与目标数据之间的KL散度')

ax.set_xticks(x)

ax.set_xticklabels(categories)

ax.legend()

在柱状图上添加数值标签

def autolabel(rects):

for rect in rects:

height = rect.get_height()

ax.annotate('{}'.format(height),

xy=(rect.get_x() + rect.get_width() / 2, height),

xytext=(0, 3), # 3 points vertical offset

textcoords="offset points",

ha='center', va='bottom')

autolabel(rects1)

autolabel(rects2)

autolabel(rects3)

显示图表

plt.show()

```

这段代码将创建一个柱状图,其中包含三组数据(双线性STM、BNN和甘),每组数据对应不同的类别。每个柱子上方的数值标签显示了KL散度的值。您可以根据需要调整颜色、标签和其他样式设置。

确保您已经安装了Matplotlib库,如果没有安装,可以通过以下命令安装:

```bash

pip install matplotlib

```

运行上述代码后,您将得到一个与您提供的图像类似的柱状图。

相关推荐
音程11 天前
Matplotlib绘制矩阵图,plt.matshow/imshow 与 ax.pcolor(pcolormesh)方法的使用
matplotlib
搏博12 天前
基于Python、tkinter、sqlite3 和matplotlib的校园书店管理系统
python·信息可视化·sqlite·matplotlib
勤奋的知更鸟14 天前
Matplotlib 绘图库使用技巧介绍
开发语言·python·matplotlib
@小红花15 天前
Matplotlib快速入门
matplotlib
仟濹18 天前
「Matplotlib 入门指南」 Python 数据可视化分析【数据分析全栈攻略:爬虫+处理+可视化+报告】
python·信息可视化·数据分析·matplotlib
Jay_2722 天前
cloudstudio腾讯云:matplotlib 设置中文字体
腾讯云·matplotlib
Gyoku Mint1 个月前
机器学习×第二卷:概念下篇——她不再只是模仿,而是开始决定怎么靠近你
人工智能·python·算法·机器学习·pandas·ai编程·matplotlib
搏博1 个月前
将图形可视化工具的 Python 脚本打包为 Windows 应用程序
开发语言·windows·python·matplotlib·数据可视化
Code_流苏1 个月前
Python趣学篇:交互式词云生成器(jieba + Tkinter + WordCloud等)
python·pillow·matplotlib·tkinter·wordcloud·jieba分词·词云生成器
AndrewHZ1 个月前
【图像处理入门】2. Python中OpenCV与Matplotlib的图像操作指南
图像处理·python·opencv·计算机视觉·matplotlib·图像操作