spatialdata-plot icon indicating copy to clipboard operation
spatialdata-plot copied to clipboard

Different plot if specifying `dpi=` in `plt.figure()` vs in `pl.show()`

Open LucaMarconato opened this issue 1 year ago • 2 comments

I have noticed that if I create a figure with plt.figure(), setting the dpi in plt.figure() leads to a smaller plot than if setting the dpi in pl.show().

I think, but to be double-checked, that the correct version is the one given by pl.show().

LucaMarconato avatar Jul 18 '24 19:07 LucaMarconato

Code to reproduce:

import spatialdata_plot
from spatialdata.datasets import blobs
import matplotlib.pyplot as plt

sdata = blobs()

# ok
plt.figure(figsize=(10, 10), dpi=72)
sdata.pl.render_points('blobs_points').pl.show()
plt.savefig('dpi_72.png')
plt.show()

# plot is larger
plt.figure(figsize=(10, 10), dpi=300)
ax = plt.gca()
sdata.pl.render_points('blobs_points').pl.show(ax=ax)
plt.savefig('dpi_300_method_1.png')
plt.show()

# plot is larger
plt.figure(figsize=(10, 10))
ax = plt.gca()
sdata.pl.render_points('blobs_points').pl.show(ax=ax, dpi=300)
plt.savefig('dpi_300_method_2.png')
plt.show()

LucaMarconato avatar Jul 18 '24 19:07 LucaMarconato

Q(@Sonja-Stockhaus) from call:

do we do anything with DPI if we're not generating the ax?

timtreis avatar Jul 24 '24 14:07 timtreis