ipython / ipython/ipykernel

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

Offen
#279 2 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
Python
Sterne
734
Forks
412
Ø Merge
1 T. 5 Std.
Gemergte PRs (30 T.)
8

Beschreibung

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.

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.