Plotly showing unnecessary space in heat map

Viewed 480

I am trying to create a heatmap. The code:

import plotly.express as px                 

fig = px.imshow(data.corr().values)              
fig.update_layout(               
    title="Correlation matrix",            
    xaxis_title="X",             
    yaxis_title="Y",                
    coloraxis_colorbar=dict(             
        title="Your Title",             
    ))               
fig.show()        

The plot: Correlation matrix

1 Answers

You can specify the size of your Figure explicitly to remove this white space if you don't want it. For example:

import numpy as np
import pandas as pd
import plotly.express as px

data = np.random.randn(10, 10)
data = pd.DataFrame(data)

fig = px.imshow(data.corr().values)
fig.update_layout(
    title="Correlation matrix",
    xaxis_title="X",
    yaxis_title="Y",
    coloraxis_colorbar=dict(
        title="Your Title"),
    width = 700, height = 700,
    autosize = False)
fig.show()

producescorrelation matrix without white space

Related