sherpa / sherpa

Fit models to your data in Python with Sherpa.
https://sherpa.readthedocs.io
GNU General Public License v3.0
155 stars 51 forks source link

Surface plots #2074

Open anetasie opened 4 months ago

anetasie commented 4 months ago

I was just looking at the images that were made with a very old version of Sherpa for the Chandra Newsletter in 2001. I'm wondering if we are able to easily make such plots now and also with a better quality than in the past.

image
DougBurke commented 4 months ago

Technically we can, as long as the backend allows it

This is related to

The issue becomes what the user-interface is (a new set of calls or allow plot_data to do it or ...) and then how do we "control" it (e.g. to rotate it and change the viewing angle and how the surface is rendered and ...).

DougBurke commented 4 months ago

We can explain to uses how to take the output of get_data_image/get_model_image etc and use it with matplotlib directly.

DougBurke commented 4 months ago

As an example, but be careful as I always get the ordering wrong (which is why I use a rectangular grid with an elliptical offset model)

dataspace2d([250, 200])
set_source(gauss2d.mdl)
mdl.xpos = 120
mdl.ypos = 70
mdl.fwhm = 50
mdl.ellip = 0.6
mdl.theta = 30 * np.pi / 180
image_model()

ds9

# access to coordinate information is not as simple as the 1D plot cases (e.g. get_data_plot) so we
# do it old-school, and hope we don't get things confused
m = get_model_image()
x = np.arange(1, 251)
y = np.arange(1, 201)
xg, yg = np.meshgrid(x, y)

from matplotlib import cm
fig, ax = plt.subplots(subplot_kw={"projection": "3d"})
ax.plot_surface(xg, yg, m.y, cmap=cm.viridis)
ax.set(xlabel="x", ylabel="y")

mpl

hamogu commented 4 months ago

We currently don't have a matplotlib image backend (images are shown in ds9). Once we have that, it's a trivial change to use surfaces instead. However, do we even want that? As @DougBurke said get_data_image plus a plotting backend of your choice can do that already. I don't think it's a good use of our time to make an interface for any and all plots that we can think of, but instead, we should provide a generic interface to make one usuable plot and leave it to the user to use functions like get_data_imge or to to inherit from out backends for other vizualization choices.

Today, I think the default way to display an image is color (as done in ds9 and as I would do it in a matplotlib-based backend for image plotting).

anetasie commented 4 months ago

@DougBurke thanks for the example. It looks great and much better quality than the old plot. I agree that we should just document this option for the users.

anetasie commented 4 months ago

btw. I will try with some images of residuals.