如何将Matplotlib图设置为可用空间的100%?

3

我尝试让Matplotlib图表覆盖笔记本中可用的所有空间。

因此,我希望该图表利用由红色框框起来的空间:

enter image description here

该代码生成了屏幕截图:

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, 
) 

然而,我希望避免硬编码arbitrarily_large_number_of_inches10,因为这可能会根据我的显示器屏幕大小而更改。

是否有类似于HTML的width=100%的等效物?类似于subplots_adjust的相对单位也可以。

感谢您的时间。


1
实际尺寸(以英寸为单位)和笔记本中所占空间的大小之间存在差异,而这还回避了笔记本是否始终具有相同的大小的问题。从 matplotlib 大小的角度来看,没有与您建议的 100% 相当的东西,但可能有办法控制它在笔记本中的显示方式?也许您可以提供有关图形如何显示以及您希望从哪个角度进行更改的详细信息? - Grismar
你是否期望左侧的图表在相同的配置下扩展宽度,变为大约3.5倍宽?在你的笔记本中,你能够访问有关视口的信息吗?你能否分享更多关于你用来创建笔记本的工具和笔记本中的代码的信息 - 它只是你分享的代码吗? - Grismar
我希望图表的两列都能够增长并填充额外的空间,就像网页元素随着窗口大小的变化而增长一样。我不知道是否可以从笔记本中获取视口信息。 - Zhao Li
在这种情况下,也许我不应该标记“jupyter-notebook”。我对Databricks不太熟悉,所以如果他们的用户界面完全不同,请随意取消标记。 - tdy
1
我对如何在jupyter-notebook中实现此操作也很感兴趣。这些笔记本中的大多数示例代码已经适用于databrick笔记本。 - Zhao Li
显示剩余3条评论
1个回答

0

看起来现在还不可能 :(


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接