CERN / TIGRE

TIGRE: Tomographic Iterative GPU-based Reconstruction Toolbox
BSD 3-Clause "New" or "Revised" License
573 stars 188 forks source link

Add show_plot option to plot-functions in Python #291

Closed tsadakane closed 3 years ago

tsadakane commented 3 years ago

Summary

A solution for #285

Add show_plot option to plot-functions in Python.

Modified

Test

Code

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

Environment

AnderBiguri commented 3 years ago

Great! I'll test it and add it, after I test #290. Thanks a lot!