Matplotlib的条形图 [英] bar chart with Matplotlib

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

问题描述

这是我的数据结构:

data = {'2013': {1:25,2:81,3:15}, '2014': {1:28, 2:65, 3:75}, '2015': {1:78,2:91,3:86 }}

我的x轴是数字 [1,2,3]

我的y轴是每个数字的数量.例如:在2013年, 1 是x轴,而数量是 25 .

My y-axis is the quantity of each number. For example: In 2013, 1 is x axis while its quantity is 25.

每年打印每个图形

我想绘制一个条形图,该条形图上使用了带有图例的matplotlib.

I would like to graph a bar chart, which uses matplotlib with legend on it.

推荐答案

import matplotlib.pyplot as plt
import pandas as pd

data = {'2013': {1:25,2:81,3:15}, '2014': {1:28, 2:65, 3:75}, '2015': {1:78,2:91,3:86 }}

df = pd.DataFrame(data)

df.plot(kind='bar')

plt.show()

我喜欢熊猫,因为它无需处理任何数据即可绘制数据并将其绘制出来.

I like pandas because it takes your data without having to do any manipulation to it and plot it.

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

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