5

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

Vivek
  • 507
  • 5
  • 15
  • Maybe there is a misconception at play, but "resolution" means how many pixels you have, because there are no half- or quarter pixels. – ImportanceOfBeingErnest Jun 13 '18 at 00:35
  • My mistake -- I thought resolution and pixel density were interchangeable. I think that what I am really after is a way to increase the pixel density while keeping the resolution constant. – Vivek Jun 13 '18 at 01:48
  • No sure, they are the same thing. What you're asking seems like you want to have 200 pixels in a 100 pixel image, which is impossible since there are no half-pixels. – ImportanceOfBeingErnest Jun 13 '18 at 02:01
  • I understand now. What I was looking for was a way to change the size of images rendered in interactive mode while retaining their quality (think the way you can change an image's dimensions in Powerpoint by dragging it). My current solution is to save the figures to my directory and then display in a Markdown cell. While I can edit the width using HTML, this solution still feels clunky. – Vivek Jun 13 '18 at 14:57
  • You can show the image with dpi=100 and save it with dpi=300. Is that what you mean? – ImportanceOfBeingErnest Jun 13 '18 at 15:02
  • Also if I want to publish the notebook, other uses might have screens with higher resolution than mine, so would nice to be able to increase the pixel density when I make the notebook so it also looks sharp for them. – wordy Jan 11 '19 at 15:33

1 Answers1

5

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

%config InlineBackend.figure_format = 'retina'

wordy
  • 539
  • 5
  • 15