【问题标题】:Python seaborn legends cut offPython seaborn 传说被切断
【发布时间】:2018-01-30 17:02:08
【问题描述】:

不幸的是,下面的 Python 代码生成的图形切断了部分图例。我怎样才能避免这种情况?我是否错过了sns 调用中的参数,或者这是由于我设置 PyCharm IDE 的方式?

import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt

df = pd.read_csv('gm_2008_region.csv')
df = df.drop('Region', axis=1)
plt.figure()
sns.heatmap(df.corr(), square=True, cmap='RdYlGn')
plt.show()

这是结果图:

.csv 文件可以在here找到。

【问题讨论】:

    标签: python pandas ubuntu matplotlib seaborn


    【解决方案1】:

    尝试如下添加plt.subplots_adjust(bottom=0.28)

    import pandas as pd
    import seaborn as sns
    import matplotlib.pyplot as plt
    
    df = pd.read_csv('gm_2008_region.csv')
    df = df.drop('Region', axis=1)
    plt.figure()
    sns.heatmap(df.corr(), square=True, cmap='RdYlGn')
    plt.subplots_adjust(bottom=0.28)
    plt.show()
    

    给你:

    【讨论】:

      【解决方案2】:

      您可能想要更改plt.figurefigsize,例如...

      import pandas as pd
      import seaborn as sns
      import matplotlib.pyplot as plt
      
      df = pd.read_csv('gm_2008_region.csv')
      df = df.drop('Region', axis=1)
      plt.figure(figsize=(12, 8))
      sns.heatmap(df.corr(), square=True, cmap='RdYlGn')
      plt.show()
      

      【讨论】:

        猜你喜欢
        • 2019-07-13
        • 2019-09-18
        • 1970-01-01
        • 2014-09-13
        • 2015-05-04
        • 2013-01-02
        • 1970-01-01
        • 2023-03-17
        • 1970-01-01
        相关资源
        最近更新 更多