【发布时间】:2021-08-11 03:24:03
【问题描述】:
我正在尝试让 Matplotlib 图形覆盖笔记本内的整个可用空间。
所以我想让图利用红框占用的空间:
这段代码生成了截图:
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_inches 硬编码为 10,这可能会根据我的显示器屏幕尺寸而改变。
是否有与 HTML 的 width=100% 等价的东西? subplots_adjust 的相对单位也可以。
感谢您的宝贵时间
【问题讨论】:
-
图形的实际大小(以英寸为单位)与它在笔记本电脑中占用的空间之间存在差异 - 如果笔记本电脑总是有相同的大小。没有相当于您从 matplotlib 大小建议的 100%,但可能有办法控制它在笔记本中的显示方式?也许您可以提供一些关于情节如何显示的详细信息,以及您希望从这个角度改变什么?
-
感谢您的建议。我已经用截图更新了这个问题,希望它可以让我更容易理解我想要完成的事情。再次感谢您的宝贵时间
-
在相同的配置下,您是否希望左侧图表的宽度扩大到大约 3.5 倍?在您的笔记本中,您是否有权访问有关视口的信息?您能否分享更多关于您用于创建笔记本的信息以及笔记本中的代码 - 仅仅是您分享的代码吗?
-
我正在使用这里托管的笔记本:community.cloud.databricks.com/login.html
-
我也会对如何为
jupyter-notebooks 执行此操作感兴趣。这些笔记本中的大部分示例代码都适用于databrick笔记本。
标签: python matplotlib jupyter-notebook