0

I have just changed this

    import matplotlib.pyplot as plt
    import numpy as np
    import numpy.ma as ma

    # ... more code here...
 
    f = plt.figure(figsize=(12,8)) #width height
    
    axarr = plt.axes([0.115,0.1,0.76,0.7]) #[left, bottom, width, height]
    axarr2=axarr.twinx()
    axarr3=axarr.twinx()

    # ... more code here...

    if TheEarlySpatialSlope2 < 0 and TheEarlySpatialSlope3 < 0:
        sentenceEarly = 'q\u2193, T\u2193'
    elif TheEarlySpatialSlope2 < 0 and TheEarlySpatialSlope3 > 0:
        sentenceEarly = 'q\u2193, T\u2191'

to italic letters:

    if TheEarlySpatialSlope2 < 0 and TheEarlySpatialSlope3 < 0:
        sentenceEarly = '$\it{q}$\u2193, $\it{T}$\u2193'
    elif TheEarlySpatialSlope2 < 0 and TheEarlySpatialSlope3 > 0:
        sentenceEarly = '$\it{q}$\u2193, $\it{T}$\u2191

and then I changed it back again. Before doing any changes, the image on the left-hand side was plotted (This is the one I want to have). When going for italic letters, I got the image on the right-hand side (thin lines, weird figure size), and also after changing things back to the first version. I've experienced this before, and only resetting the system management controllers (SMC) and NVRAM / PRAM in MacOs back helped. Now, resetting does not give me the plots back.

changed fig size without doing anything

I cannot give you a mini-example as my code is way too long, and obviously, it is not about the code itself, as a copy of my python file I didn't change anything on is now producing weird images as well. It seems my computer changed settings or something. Apparently, other users had this problem:

[matplotlib figures scale weirdly / can't get a nice small figure][2]
[Attempt to create a dynamically changing plot in console and notebook][3]
[figure changes size at end of loop if drawn dynamically][4]
[Figure doesn't fill canvas in interactive plot with Matplotlib in Jupyter notebook][5]

I am just a beginner in python and don't understand the in-deep hacks, so I would kindly ask you whether you could point out the solution for my problem.

KMFWeb
  • 55
  • 1
  • 8
  • Yes, I've seen this sort of artifact pop up. I see that you say you cannot give a mini-example, but how portable is your code? Rather than refreshing your system, maybe you can run your code on a remote 'fresh' machine? I have two repos [here](https://github.com/fomightez/animated_matplotlib-binder) and [here](https://github.com/fomightez/3Dscatter_plot-binder) that you can go to and get fairly up-to-date plotting-cable session by pressing `launch binder`. Both of those default to opening in the 'classic' notebook interface - click on the Jupyter logo in the upper left to switch to JupyterLab. – Wayne Feb 02 '22 at 17:39
  • Continued.... The JupyterLab interface allows easy drag-n-drop from your local system into the file navigator on the left side panel. You can put your notebook and data there (hopefully) and run (hopefully). Use `%pip install` and `%conda install` in the cells in the notebook if you need to install anything that isn't there. **Download anything you make that's useful as they are temporary sessions and timeout after ten minutes of inactivity.** – Wayne Feb 02 '22 at 17:42
  • 12x8 is a big figure and your second plot looks properly sized assuming you are using 12 pt fonts. It it’s impossible to say why your figures change size when you don’t say anything about your environment or how you are trying to display the figures. – Jody Klymak Feb 02 '22 at 20:18
  • Thanks, @Wayne! My code isn't yet very portable, but I'll try. @Jody Klymak, thanks for your hint! I've deleted "figsize=(12,8)" out, and got my nice plots back, with italic letters! However, there is a huge white space at the top of the graph now, and I would like to crop my figure to minimalize white borders. Is there another way than plt.figure(figsize=(12,8)) ? – KMFWeb Feb 02 '22 at 22:12

1 Answers1

0

I replaced

f = plt.figure(figsize=(12,8))

with

f = plt.figure()

and added

bbox_inches = 'tight'

when saving the image to crop it:

plt.savefig(TheFile+".eps", bbox_inches = 'tight')
KMFWeb
  • 55
  • 1
  • 8