【发布时间】:2019-10-02 12:29:21
【问题描述】:
我想通过字典使用 matplotlib 绘制条形:
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
plt.style.use('ggplot')
import numpy as np
dictionary = {0: 0, 1: 13.2, 2: 29.7, 3: 43, 4: 52}
plt.bar(list(dictionary.keys()), dictionary.values(), color='red')
plt.xlabel('X')
plt.ylabel('Y(%)')
plt.show()
但是,我想得到这样的照片:
你能帮帮我吗?提前谢谢你。
【问题讨论】:
-
vertical & horizontal lines in matplotlib 的可能重复项;您想要的功能是
axhline,链接的问题提供了示例用法。 -
@ymbirtt,事实并非如此。
-
你是对的,看起来
plot更符合你的要求,尽管我标记为重复的问题确实描述了如何在其接受的答案中使用它。
标签: python