KDIDS 2021-09-22 09:52 采纳率: 45.5%
浏览 21

Seaborn如何把两张数据源不同的图合并?

French_movie_genre_count = French_movies['Genre_count']
non_French_movies_genre_count = non_French_movies['Genre_count']
fig, ax = plt.subplots(1,2)
plt.figure(figsize=(20, 16))
sns.countplot(x = French_movie_genre_count, color = 'blue', ax = ax[0])
sns.countplot(x = non_French_movies_genre_count, color = 'green', ax=ax[1])
fig.show()

如何把这来个图放到一个表里啊?
把下面这两个分开的图 合并到一个图里面 最好能归一化 变成百分比

img

  • 写回答

1条回答 默认 最新

  • CSDN专家-HGJ 2021-09-22 16:25
    关注

    先转换一下数据,换算成百分比,使用matplotlib的函数直接绘制,将主轴设置成百分比刻度,代码这样写,:

    import pandas as pd 
    import matplotlib.pyplot as plt
    import seaborn as sns
    import numpy as np
    import matplotlib.ticker as mtick
    French_movies=pd.read_csv('French_movies.csv')
    non_French_movies = pd.read_csv('non_French_movies.csv')
    French_movie_genre_count = French_movies['Genre_count'].apply(
        lambda x: x/French_movies['Genre_count'].sum())
    non_French_movies_genre_count = non_French_movies['Genre_count'].apply(
        lambda x: x/non_French_movies['Genre_count'].sum())
    df = pd.DataFrame({'french_movie_count': French_movie_genre_count, 'non_french_movie_count': non_French_movies_genre_count})
    print(df)
    ax=df.plot(kind='bar',
              figsize=(12, 6),
              title='French_movies and non_French_movies',
            rot=0)
    ax.yaxis.set_major_formatter(mtick.PercentFormatter(xmax=1))
    plt.show()
    

    运行效果图:

    img

    如果回答对你有帮助,请点击我回答的右上方采纳按钮,给予采纳一下

    评论

报告相同问题?

问题事件

  • 创建了问题 9月22日