如何使用Python库绘制条形图

问题描述 投票:0回答:1

我是 phyton 新手,我想知道如何使用 csv 文件绘制条形图。

我已经导入了matplotlib.pyplot,我已经编写了df = read_csv(“csv需要的目录”)。 我希望有人告诉我下一步,我将感谢您的帮助。 详细的解释将不胜感激。 谢谢。

python matplotlib seaborn bar-chart read.csv
1个回答
0
投票

您可以使用 Matplotlib 的 bar 函数绘制带有适当标签和标题的条形图。

import matplotlib.pyplot as plt
import pandas as pd

df = pd.read_csv("directory_of_csv_file.csv")
plt.bar(df["categories"], df["values"])
plt.xlabel("Categories")
plt.ylabel("Values")
plt.title("Bar Chart")
plt.show()
© www.soinside.com 2019 - 2024. All rights reserved.