如何创建可以从中创建条形图的系列 [英] How do i create a series that I can create a bar chart from
本文介绍了如何创建可以从中创建条形图的系列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个名字列表:['joe','brian','stephen']
I have a list of names: ['joe','brian','stephen']
我想在jupyter中创建一个条形图,以名称作为索引,并在条形图中显示每个名称中字母的数量.如何创建一个可以调用".plot(kind ='bar')"的系列,并获得所描述的条形图?
i would like to create a bar chart in jupyter with names as indexes and the bar showing the numbers of letters in each name. How do I create a series which I can call ".plot(kind='bar')" on and get a bar chart like described?
推荐答案
import numpy as np
import matplotlib.pyplot as plt
bars = ['joe','brian','stephen']
height = [len(m) for m in bars]
y_pos = np.arange(len(bars))
plt.bar(y_pos, height, color=(0.2, 0.4, 0.6, 0.6))
plt.xticks(y_pos, bars)
plt.show()
这篇关于如何创建可以从中创建条形图的系列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文