我知道如何在R中执行此操作,并在下面提供了代码。我想知道如何做与Python Matplotlib中下面提到的类似的事情或使用任何其他库
library(ggplot2)
ggplot(dia[1:768,], aes(x = Glucose, fill = Outcome)) +
geom_bar() +
ggtitle("Glucose") +
xlab("Glucose") +
ylab("Total Count") +
labs(fill = "Outcome")
最佳答案
请考虑下面的示例,该示例使用seaborn。
import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
# generate random data
data = {'Glucose': np.random.normal(5, 10, 100),
'Outcome': np.random.randint(2, size=100)}
df = pd.DataFrame(data)
# plot
fig, ax = plt.subplots(figsize=(10, 10))
for group in df.Outcome.unique():
sns.distplot(df.loc[df.Outcome == group, 'Glucose'],
kde=False, ax=ax, label=group)
ax.set_xlabel('Glucose')
ax.set_ylabel('Total Count')
ax.set_title('Glucose')
ax.legend()