相关疑难解决方法(0)

如何将图添加到子图 matplotlib

我有这样的情节

fig = plt.figure()
desire_salary = (df[(df['inc'] <= int(salary_people))])
print desire_salary
# Create the pivot_table
result = desire_salary.pivot_table('city', 'cult', aggfunc='count')

# plot it in a separate step. this returns the matplotlib axes
ax = result.plot(kind='bar', alpha=0.75, rot=0, label="Presence / Absence of cultural centre")

ax.set_xlabel("Cultural centre")
ax.set_ylabel("Frequency")
ax.set_title('The relationship between the wage level and the presence of the cultural center')
plt.show()
Run Code Online (Sandbox Code Playgroud)

我想将此添加到subplot. 我试试

fig, ax = plt.subplots(2, 3)
...
ax = result.add_subplot()
Run Code Online (Sandbox Code Playgroud)

但它返回 AttributeError: 'Series' object has no attribute …

python matplotlib pandas

3
推荐指数
1
解决办法
2万
查看次数

如何使用分类轴在条形图上叠加数据点

目标:我试图使用 Seaborn 在具有多个分组条形图的图中显示各个数据点。

问题:我尝试使用条形图的猫图和各个数据点的猫图来完成此操作。但是,这会生成 2 个数字:一个包含条形图,另一个包含各个数据点。

问题:有没有办法使用 Seaborn 在同一图中将各个数据点与条形图一起显示?

这是我的代码生成两个单独的数字:

import seaborn as sns
tips = sns.load_dataset("tips")

g = sns.catplot(
    x="sex", 
    y="total_bill", 
    hue="smoker", 
    row="time", 
    data=tips, 
    kind="bar", 
    ci = "sd", 
    edgecolor="black",
    errcolor="black",
    errwidth=1.5,
    capsize = 0.1,
    height=4, 
    aspect=.7,
)

g = sns.catplot(
    x="sex", 
    y="total_bill", 
    hue="smoker", 
    row="time", 
    data=tips, 
    kind="strip", 
    height=4, 
    aspect=.7,
)
Run Code Online (Sandbox Code Playgroud)

输出:

我的输出

问题:有没有办法使用 Seaborn 在同一图中将各个数据点与条形图一起显示?

python bar-chart seaborn facet-grid stripplot

3
推荐指数
1
解决办法
4422
查看次数

如何创建带有子图和子图的图

我正在用Python学习乳腺癌分类数据集。我正在尝试为每个特征绘制直方图,如何将这些直方图分为三组?就像下面的截图一样:

我想要实现的目标

我想要实现的目标

这是我使用的代码:

from sklearn.datasets import load_breast_cancer  # sample data
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt

data = load_breast_cancer()

# Turn the feature data into a dataframe
df = pd.DataFrame(data.data, columns = data.feature_names)

# Add the target columns, and fill it with the target data
df["target"] = data.target

# display(df.head())
   mean radius  mean texture  mean perimeter  mean area  mean smoothness  mean compactness  mean concavity  mean concave points  mean symmetry  mean fractal dimension  radius error …
Run Code Online (Sandbox Code Playgroud)

python data-visualization matplotlib subplot seaborn

1
推荐指数
1
解决办法
2306
查看次数

python绘制多个直方图

我有一个包含 30 个变量的数据框 X,v1, v2 ... v30并且 col_name=[v1,v2.....v30]

对于每个变量,我想绘制直方图以了解变量分布。但是,编写代码来一个一个地绘制太手动了,我可以使用 for 循环之类的东西一次绘制 30 个直方图吗?

例如:

for i in range(30):
  hist(np.array(X[col_name[i]]).astype(np.float),bins=100,color='blue',label=col_name[i],normed=1,alpha=0.5)
Run Code Online (Sandbox Code Playgroud)

我怎样才能做到这一点?就像一页图表(每个图表都有标题和标签),这样我就可以向下滚动阅读。

python plot matplotlib

0
推荐指数
1
解决办法
1万
查看次数