geoschem / gcpy

Python toolkit for GEOS-Chem. Contains basic plotting scripts, plus the suite of GEOS-Chem benchmarking utilities.
https://gcpy.readthedocs.io
Other
51 stars 24 forks source link

Now let user specify X11 backend with "export MPLBACKEND="tkagg" (or "MacOSX") #275

Closed yantosca closed 1 year ago

yantosca commented 1 year ago

This is the companion PR for issue #269. In example scripts gcpy/examples/plotting/plot_single_panel.py and gcpy/examples/plotting/plot_comparisons.py, we had set the X11 backend for Matplotib to tkagg (from the Tcl/Tk library). The X11 backend is necessary so that these example scripts can open a plot window on the screen.

However, the tkagg backend is not compatible on MacOSX. Therefore, rather than hardcoding a value for the X11 backend, we will let the user pick the proper value by setting either:

export MPLBACKEND="tkagg"        
or
export MPLBACKEND="MacOSX" 
yantosca commented 1 year ago

We will also need to update the GCPy RTD documentation accordingly.

yantosca commented 1 year ago

FYI, I was able to get a plot by setting

export MPLBACKEND="macosx"

in my Mac terminal window, and then using this test program from the matplotlib doc:

import matplotlib.pyplot as plt

fig, ax = plt.subplots()

fruits = ['apple', 'blueberry', 'cherry', 'orange']
counts = [40, 100, 30, 55]
bar_labels = ['red', 'blue', '_red', 'orange']
bar_colors = ['tab:red', 'tab:blue', 'tab:red', 'tab:orange']

ax.bar(fruits, counts, label=bar_labels, color=bar_colors)

ax.set_ylabel('fruit supply')
ax.set_title('Fruit supply by kind and color')
ax.legend(title='Fruit color')

plt.show()
Screenshot 2023-11-10 at 2 25 44 PM

Also using:

export MPLBACKEND="qt5agg" 

should work too.

yantosca commented 1 year ago

I also suspect the version of the MacOSX operating system might matter.

yantosca commented 1 year ago

Update: On MacOSX Sonoma 14.1.1, I was able to set

export MPLBACKEND=tkagg

in both the Mac terminal window and on a remote machine (Cannon). The sample program above was able to display the plot shown in the previous comment to the screen. I wonder if updating the OS solves the issue.

msulprizio commented 1 year ago

Update: On MacOSX Sonoma 14.1.1, I was able to set

export MPLBACKEND=tkagg

in both the Mac terminal window and on a remote machine (Cannon). The sample program above was able to display the plot shown in the previous comment to the screen. I wonder if updating the OS solves the issue.

I was finally able to get it to work using this solution. I think the key was executing the command in the Mac terminal window as well. Thanks! Good to merge now!