How to set Matplotlib figure to 100% of available space?

Viewed 156

I'm trying to get a Matplotlib figure to span the entire space available inside a notebook.

So I want to have the figure make use of the space taken up by the red box:

enter image description here

This code generated the screenshot:

from sklearn.datasets import load_iris 
import numpy as np 
import pandas as pd 

iris_data = load_iris() 
join_pd_df = pd.DataFrame( 
  data = np.c_[ 
    iris_data['data'], 
    iris_data['target'], 
  ], 
  columns = iris_data['feature_names'] + ['target'] 
) 

import matplotlib.pyplot as plt 
import seaborn as sns 

list_of_features = [ 
  "sepal length (cm)", 
  "sepal width (cm)", 
  "petal length (cm)", 
] 

number_of_charts = 2 
number_of_features = len(list_of_features) 
arbitrarily_large_number_of_inches = 10 # I want to avoid hard-coding this value
fig, axes = plt.subplots( 
  number_of_features, 
  number_of_charts, 
  figsize=(arbitrarily_large_number_of_inches, arbitrarily_large_number_of_inches) 
) 

for iteration, feature in enumerate(list_of_features): 
  sns.regplot(x="target", y=feature, data=join_pd_df, ax=axes[iteration, 0]) 
  sns.boxplot(x=feature, y="target", data=join_pd_df, ax=axes[iteration, 1]) 

plt.subplots_adjust( 
  left = 0.1, 
  right = 0.9, 
  top = 0.9, 
  bottom = 0.1, 
  wspace = .4, 
  hspace = .4, 
) 

However, I would like to avoid hardcoding arbitrarily_large_number_of_inches to 10, which could change based on my monitor screen size.

Is there something equivalent to HTML's width=100%? Something like the relative units for subplots_adjust would work as well.

Thank you for your time

1 Answers

It seems like it is not possible at this time :(

Related