如何在 python 中使用 matplotlib 在 python 中绘制带有标签的简单条形图?

how to draw a simple bar chart with labels in python using matplotlib in python?

我有如下数据

>>>x = [transactional,promotional]  
>>>y = [3198293, 189910]

我需要画一个简单的条形图?我怎么能够?

这是我试过的方法

>>>import matplotlib.pyplot as plt
>>>plt.bar(x, y ,width=0.90)  

只是我需要绘制一个带有标签的条形图,x 轴是 x,y 轴是 y。
尝试了一些方法,但它是
显示一些随机图表....请帮助我。

下面的代码生成下图:

import numpy as np
import matplotlib.pyplot as plt

# Specify data / labels
y = [3198293, 189910]
xlabels = ['transactional','promotional']
bar_width = 0.90

x = np.arange(len(y))

fig, ax = plt.subplots()
ax.bar(x, y, width=bar_width)
ax.set_xticks(x + (bar_width/2.0))
ax.set_xticklabels(xlabels)
plt.show()

这只是一个基本示例,http://matplotlib.org/examples/ 中有更详细的示例。

您可能对 barchart_demo.py

特别感兴趣