Search code examples
pythonmatplotlibseabornpearson-correlation

How to adjust the size of graph in python (Matplotlib)


I have a dataset containing 200+ features. I want to visualize a heatmap for Pearson Correlation using sns and matplotlib. The graph I created looks very small and is not displaying properly(see image below)

1) My question is how to adjust the graph? 2) Is this the right way to visualize a dataset with over 200+ features?

This is my code:

#!/usr/bin/env python
# coding: utf-8

# In[105]:
import os
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns



# In[106]:


# Load data from path

D_rt_none = pd.read_pickle("data/170408-2141-rt-none.pkl")
D_rt_nginx = pd.read_pickle("data/170408-2154-rt-nginxlb.pkl")
D_rt_socat = pd.read_pickle("data/170408-2206-rt-socat.pkl")
D_rt_redir = pd.read_pickle("data/170408-2232-rt-squid.pkl")
D_rt_nginx_socat_redir = pd.read_pickle("data/170409-0718-rt-nginxlb-socat-squid.pkl")
D_rt_socat_redir_nginx = pd.read_pickle("data/170409-1606-rt-socat-squid-nginxlb.pkl")
D_rt_redir_nginx_socat = pd.read_pickle("data/170410-0054-rt-squid-nginxlb-socat.pkl")


# In[107]:


def main():
    print("NFV Data Visualization")
    print(D_rt_nginx.head())
    print("Info")
    print(D_rt_nginx.info())
    print("Describe")
    print(D_rt_nginx.describe())
    corr = D_rt_nginx.corr()
    plt.figure(figsize=(50,50))
    ax = sns.heatmap(
                 corr,
                 vmin=-1, vmax=1, center=0,
                 cmap=sns.diverging_palette(20, 220, n=200),
                 square=True
                 )
    ax.set_xticklabels(
                   ax.get_xticklabels(),
                   rotation=45,
                   horizontalalignment='right'
                   );
    plt.show()


# In[110]:





# In[109]:


main()

Output

Graph


Solution

  • Like @gmds suggested in the comments, I had to group them separately and generate the graph.