ipython / ipython/ipykernel

matplotlib figures scale weirdly / can't get a nice small figure

未關閉
#279 2 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
主要語言
Python
星號
734
分支
412
平均合併
1 天 5 小時
30 天內合併 PR
8

描述

I'm using Jupyter notebook with anaconda and yesterday updated ipykernel (from I think 4.3.x to 4.6.1).
Before, when I plotted something, by default I got a fairly small figure like below:
fig_before
Suddenly, the figures now are really big (by default take up the whole width of the browser) and I can't really scale them down, at least not in a pretty way. I'm using `%matplotlib inline` and for example when I specify `plt.rcParams['figure.figsize'] = (10,6)` I get a nice large figure as below:
fig_10_6
However, if I'm trying to make the figure smaller, e.g. with `plt.rcParams['figure.figsize'] = (2,1.2)`, while I do get a smaller figure, it looks awful as it doesn't scale accordingly:
fig_2_12

the code that's used to generate the figures is the following:
```
def plot_mnist(X, y, X_test=None, y_test=None, title=None):
plt.figure()
colorlist = get_colors(10)
# Scale and visualize the embedding vectors
x_min, x_max = np.min(X, 0), np.max(X, 0)
if (X_test is not None) and (y_test is not None):
x_min, x_max = np.min(np.array([x_min, np.min(X_test, 0)]), 0), np.max(np.array([x_max, np.max(X_test, 0)]), 0)
X_test = (X_test - x_min) / (x_max - x_min)
X = (X - x_min) / (x_max - x_min)
if (X_test is not None) and (y_test is not None):
for i in range(X_test.shape[0]):
plt.text(X_test[i, 0], X_test[i, 1], str(y_test[i]),
color=colorlist[y_test[i]],
fontdict={'weight': 'medium', 'size': 'smaller'},
alpha=0.4)
for i in range(X.shape[0]):
plt.text(X[i, 0], X[i, 1], str(y[i]),
color=colorlist[y[i]],
fontdict={'weight': 'medium', 'size': 'smaller'},
alpha=1.)
plt.xticks([]), plt.yticks([])
plt.xlim(-0.05, 1.05)
plt.ylim(-0.05, 1.05)
if title is not None:
plt.title(title)
```

Since the figures scale nicely when I decrease the width of the browser window, I'm assuming the nice way to specify the size of the figures would be to tell the notebook how much of the default width of the browser window it should use for the figure but I'm not sure if or where I could find such a setting?
I guess it might be nice if such a matplotlib inline specification would also be independent of the actual figure size, as I might want to have a large figure to save it in high quality somewhere else but then still only display a smaller figure in the notebook.

貢獻指南

開啟貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。