Vivek
Vivek

Reputation: 569

Increase resolution of figure while preserving dimensions in Python matplotlib

I have created a figure using the following method:

import matplotlib.pyplot as plt
%matplotlib inline
fig1 = plt.figure(figsize=(2, 2), dpi=100)

I want to increase the resolution of the figure, so I increased the dpi of fig1 from 100 to 200. However, this changed the pixel dimensions from (200, 200) to (400, 400), which is something I do not want. If I let dpi=200 and figsize=(1, 1), the pixel dimensions remains (200, 200), but the image looks funny. Please see the output from my Jupyter notebook here.

Is there a way in Matplotlib to increase fig1's resolution without altering its pixel dimension when rendered in Jupyter?

(Note: the code I used for generating the figures linked to above came from this question.)

Upvotes: 4

Views: 1780

Answers (1)

wordy
wordy

Reputation: 559

Specifically in the case of 2x (e.g. for retina screens), yes, use

%config InlineBackend.figure_format = 'retina'

Upvotes: 4

Related Questions