Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Nov 16, 2023

Conversation

yantosca
Copy link
Contributor

@yantosca yantosca commented Nov 9, 2023

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" 

gcpy/examples/plotting/plot_comparisons.py
- Remove import for matplotlib.use as mpl_use
- Remove statement calling mpl_use("tkagg")

gcpy/examples/plotting/plot_single_panel.py
- Remove import for matplotlib.use as mpl_use
- Remove statement calling mpl_use("tkagg")
- Fixed error in calling rename_and_flip_gchp_rst_vars; now pass
  dset to this function. This was a cut-n-paste error.

CHANGELOG.md
- Updated accordingly
@yantosca yantosca requested a review from msulprizio November 9, 2023 19:05
@yantosca yantosca self-assigned this Nov 9, 2023
@yantosca yantosca added topic: Colors and Display Issues pertaining to color scales or other display issues category: Bug Fix Fixes a bug that was previously reported labels Nov 9, 2023
@yantosca yantosca added this to the 1.4.0 milestone Nov 9, 2023
@yantosca
Copy link
Contributor Author

yantosca commented Nov 9, 2023

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

@yantosca
Copy link
Contributor Author

yantosca commented Nov 10, 2023

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
Copy link
Contributor Author

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

@yantosca
Copy link
Contributor Author

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
Copy link
Contributor

msulprizio commented Nov 15, 2023

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!

@msulprizio msulprizio merged commit d10ffb7 into dev Nov 16, 2023
2 of 5 checks passed
@msulprizio msulprizio deleted the bugfix/x11-backend branch November 16, 2023 18:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: Bug Fix Fixes a bug that was previously reported topic: Colors and Display Issues pertaining to color scales or other display issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG/ISSUE] "Cannot load backend 'TkAgg'" error when trying to regrid restart from lat-lon to cube sphere
2 participants