Barplot 2分类变量[关闭]

问题描述 投票:-2回答:1

我有两个分类变量,我想绘制这样的东西:

Plot

python pandas matplotlib
1个回答
1
投票

你用熊猫标记了你的问题,所以我假设你的数据存储在一个pandas数据帧中。

在这里,我将制作一些可能与您的数据相似或不相似的数据:

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

detect = np.array([4e6, 5e5])
no_detect = np.array([3.75e6, 6e5])

df = pd.DataFrame(np.array([detect, no_detect]).T, columns=['Has Detections', 'No Detections'])

熊猫拥有内置的绘图程序,可以轻松实现您想要的情节。

fig, ax = plt.subplots(1, 1)
df.plot.bar(rot=0, ax=ax)
ax.set_ylabel('Counts')
ax.set_xlabel('Census')

这给了我下图:

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.