Closed tsadakane closed 3 years ago
A solution for #285
Add show_plot option to plot-functions in Python.
plotImg
plotProj
import tigre import numpy as np import matplotlib import matplotlib.pyplot as plt from tigre.utilities import sl3d geo = tigre.geometry_default(high_resolution=False) angles = np.linspace(0, 2 * np.pi, 30) head = sl3d.shepp_logan_3d(list(geo.nVoxel)) projections = tigre.Ax(head, geo, angles) print(f"matplotlib.get_backend()= {matplotlib.get_backend()}") backend_orig = matplotlib.get_backend() # "Qt5Agg" # Test plotImg ## Show matplotlib.use(backend_orig) # "Qt5Agg" is set. tigre.plotImg(head, dim="Z", slice=head.shape[0]//4) # shown ## Set non-GUI matplotlib backend matplotlib.use("agg") # tigre.plotImg(head, dim="Z", slice=head.shape[0]//2) # not shown tigre.plotImg(head, dim="Y", savegif="Yslice.gif") # plot not shown on screen, but file is saved, # Test plotProj ## Show. matplotlib.use(backend_orig) # "Qt5Agg" is set. tigre.plotProj(projections, angles) # shown ## Set non-GUI matplotlib backend matplotlib.use("agg") tigre.plotSinogram(projections, projections.shape[1]//2) # not shown
Great! I'll test it and add it, after I test #290. Thanks a lot!
Summary
A solution for #285
Add show_plot option to plot-functions in Python.
Modified
plotImg
,plotProj
detects the matplotlib backend end and if it is a non-GUI backend, they don't call plt.show().Test
Code
Environment