spedas / pyspedas

Python-based Space Physics Environment Data Analysis Software
https://pyspedas.readthedocs.io/
MIT License
149 stars 58 forks source link

qt plot squashes yaxis labels #798

Open hsalinasGIT opened 6 months ago

hsalinasGIT commented 6 months ago

HI Good People, I noticed that whenever I switch from matplotlib inline plotting to using qt-plotting (to use it zoom function), the yaxis panel sizes and labels get squashed and does not retain the ysize panels I set when in-line plotting. Is there a way to retain the tplot panel size dimensions I set when using the qt-plot functionality or that feature yet to be established?

(Attatched are some tplots I made when doing matplotlib inline and matplotlib qt) inline_plot qt_example

jameswilburlewis commented 6 months ago

Could you include.a code sample that shows how you're setting the plot options and making the plots for both cases, so we can better reproduce the issue and see what we can do about it?

hsalinasGIT commented 6 months ago

Here's my coding sample:

%matplotlib inline #plot figures in command line
#%matplotlib qt #plot figures in interactive pop-up window

import matplotlib.pyplot as plt
import pytplot
import pyspedas
from pytplot import tplot, tlimit # plot said tplot variables and specify xrange

fig, axes = tplot(['mms1_dis_energyspectr_omni_fast', 'mms1_des_energyspectr_omni_fast', 
       'fpi_num_density','mms1_dis_bulkv_gse_fast','mms1_edp_dce_gse_brst_l2', 'mms1_edp_dce_par_epar_brst_l2',
    'mms1_fgm_b_gse_brst_l2_bvec', 'mms1_scm_acb_gse_scb_brst_l2'], xsize=15, ysize=30, return_plot_objects=True)
fsize = 14 #fontsize of axis labels/ticks
        #ion & electron energy spectra tplot panels
axes[0].set_ylabel('',fontsize = fsize)
axes[0].legend(title = 'Ion Engy Spectra [eV]',title_fontsize = legsize-2, loc = 'lower left', shadow = True)
axes[1].set_ylabel('',fontsize = fsize)
axes[1].legend(title = 'Elec Engy Spectra [eV]',title_fontsize = legsize-2, loc = 'upper left', shadow = True)
        # ion density tplot panel
ach_cc = r'$cm^{-3}$'
axes[2].set_ylabel('FPI Density\n[%s]'%(ach_cc),fontsize = fsize)
        #GSE ion velocity tplot panel
axes[3].set_ylabel('Ion Velocity\n[km/s]',fontsize = fsize)
        #GSE Efield tplot panels
axes[4].set_ylabel('EDP Efield\n[mV/m]',fontsize = fsize)
ach_Epar = r'$E_\parallel$'
axes[5].set_ylabel('%s\n[mV/m]'%(ach_Epar),fontsize = fsize)
        # GSE Bfield tplot panel
axes[6].set_ylabel('FGM BField\n[nT]',fontsize = fsize)
        # SCM Bfield tplot panels
axes[7].set_ylabel('SCM BField\n[nT]',fontsize = fsize)
achJcos = r'$(\vec{J}\cdot\hat{r})_{2D}$'
achJunit = r'[$\mu A/m^2$]'  
axes[8].set_ylabel('Electric Current\n%s'%(achJunit), fontsize = fsize)
 for i in range(2, len(axes)):
     axes[i].legend(prop={'size': legsize-2}, loc = 'upper right', shadow = True)

Here is how I'm creating my tplots. For in-line plotting, I comment out the "matplotlib qt" line and do vice versa when I want the qt-plot. Hope this info helps in reproducing my problem.

jameswilburlewis commented 6 months ago

Thanks for the code sample! We'll take a look. At first glance, it looks like qt is treating the font sizes and plot dimensions differently, compared to the inline version. I'm not sure we can do anything about that within tplot, but we'll check it out!

hsalinasGIT commented 3 months ago

Hi ya'll, Although not a fix for matplotlib inline. Thanks to this stackexchange discussion (https://stackoverflow.com/questions/43545050/using-matplotlib-notebook-after-matplotlib-inline-in-jupyter-notebook-doesnt). I have learned that using:

%matplotlib notebook
import matplotlib.pyplot as plt

Gives an interactive plot window with the zoom feature and preserves the defined y/xaxis panel sizes.