'How to keep the same pixel size with scatter_density function in a zoomed subplot

I'm trying to create a zoomed subplot of the "scatter_density" figure, with the same pixel size. So far, I can't get same pixel sizes : subplot1 and subplot 2 have different density pixel sizes, imposing the same DPI to both figure (10) (cf. figure)

figure : FIP density

I share a part of of my code (without the data import section). There's a lot of extra code, that I did not remove to stay coherent with the figure.

from __future__ import division
from scipy import *            
from pylab import *
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
import math as m
import numpy as np
import bisect
import matplotlib.patches as patches
import mpl_scatter_density

DPI_sub1=10
DPI_sub2=10

fig = plt.figure(figsize=(12.0, 8.0))
plt.subplots_adjust(bottom = 0., left = 0, top = 1., right = 1)

sub1 = fig.add_subplot(2,1,1,projection='scatter_density') 
density=sub1.scatter_density(gpMAX_S_Hydro, gpTau_oct, cmap=white_viridis,     dpi=DPI_sub1,label=legend_GYR)
fig.colorbar(density, label='$<FIP>_{GYR02}$ par pixel')
sub1.scatter(xCS, yCS, color = 'red',label='$<FIP>_{Critique}$')
sub1.plot(xSB,ySB,'--', label='$CR_{SB}$',color='darkred') 
sub1.set_xlim(Xmin_sub1, Xmax_sub1)
sub1.set_ylim(Ymin_sub1, Ymax_sub1)
sub1.grid(axis = 'y',linewidth=0.2)
sub1.set_ylabel('$\u03C4_{oct,a}$', labelpad = 15)
sub1.legend(loc='upper left')
string='$CS_{SB}$ = '+str('%.2f' % CS_SB_GYR02)
plt.text(71, 100, string, size=LEGEND_SIZE)

sub3 = fig.add_subplot(2,1,2,projection='scatter_density')
density=sub3.scatter_density(gpMAX_S_Hydro, gpTau_oct, cmap=white_viridis,dpi=DPI_sub2,label=legend_GYR)
fig.colorbar(density, label='$<FIP>_{GYR02}$ par pixel')
sub3.plot(xSB,ySB,'--', label='$CR_{SB}$', color='darkred') 
lab='$<FIP>_{GYRd20}$'
sub3.set_xlim(Xmin_sub3, Xmax_sub3)
sub3.set_ylim(Ymin_sub3, Ymax_sub3)
sub3.set_xlabel('$\sigma_{H,max}$ (MPa)', labelpad = 15)
sub3.set_ylabel('$\u03C4_{oct,a}$', labelpad = 15)
sub3.grid(axis = 'y',linewidth=0.2)
sub3.fill_between((Xmin_sub1,Xmax_sub1), Ymin_sub1, Ymax_sub1, facecolor=zoomcolor, alpha=0.2)
con1 = patches.ConnectionPatch(xyA=(Xmin_sub1, Ymin_sub1), coordsA=sub1.transData,    xyB=(Xmin_sub1,Ymax_sub1), coordsB=sub3.transData, color = zoomcolor)
fig.add_artist(con1)
con2 = patches.ConnectionPatch(xyA=(Xmax_sub1, Ymin_sub1), coordsA=sub1.transData, xyB=(Xmax_sub1, Ymax_sub1), coordsB=sub3.transData, color = zoomcolor)
fig.add_artist(con2)

I'm looking for a plot (subplot1) with the same pixel size as subplot2, and thus to have the same range of scaling bar in both figures.

I tried to work with pixels=figure size (inches) * dpi, but I did not found any solution.

Does anyone have any idea ?

Thank you, Marie.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source