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

Add MultiPanelFITSFigure class? #174

Open
cdeil opened this issue Feb 19, 2014 · 7 comments
Open

Add MultiPanelFITSFigure class? #174

cdeil opened this issue Feb 19, 2014 · 7 comments

Comments

@cdeil
Copy link
Contributor

cdeil commented Feb 19, 2014

I would like to add some code to aplpy to make it easy to plot very wide survey images in multiple panels, like in this example.

I do have some (very messy) code to do it where the user has to sub-class to make a plot:
https://gist.github.com/cdeil/9090342

Would that be a welcome addition or is this too specialized?
If yes, what would be a nice API for this?

The current implementation seems overly complicated, plus I think it's very slow and memory intensive because for each panel there is a copy of the full survey image data ... any advice how to do this better?
#88 might help.

@keflavich
Copy link
Member

I would welcome it. This has been a common need in my daily work; last time I did this I think I did it in IDL!

Maybe it would be best to have a wrapper that splits up the FITS file into sub-files to minimize memory usage? This would remove some of the flexibility aplpy provides, but would improve performance.

Alternatively, maybe there's no need to do anything beyond #88, but instead include this in https://github.com/aplpy/aplpy-examples/ as a recipe?

I haven't looked at #88 in a long time; @cdeil, any chance you want to help add some tests?

@astrofrog
Copy link
Member

I think this would be useful to have at the very least in http://aplpy.readthedocs.org/en/v0.9.11/howtos.html - whether it should make it into the core package is not as clear, but if you could already write a HOWTO with the simplest possible code, then we can see how we can generalize it to include it in the actual package.

@cdeil
Copy link
Contributor Author

cdeil commented Mar 12, 2015

I still haven't figured out how to structure code for plotting multiple sky images on one matplotlib Figure well.
The issue @adonath and I are having is that we want to write one function per sub-plot (plot_ax_1 and plot_ax_2 in the example below) and then combine these sub-plots in various ways (e.g. make_plot_1 in the example below).

import matplotlib.pyplot as plt

def plot_ax_1(fig, rect):
    ax = fig.add_axes(rect)
    ax.plot([1,2,3], [2,3,3], color='blue')

def plot_ax_2(fig, rect):
    ax = fig.add_axes(rect)
    ax.plot([1,2,3], [2,3,3], color='red')

def make_plot_1():
    fig = plt.figure(figsize=(10, 10))
    ax1 = plot_ax_1(fig, rect=[0.1, 0.2, 0.3, 0.4])
    ax2 = plot_ax_2(fig, rect=[0.5, 0.6, 0.1, 0.2])
    fig.savefig('/tmp/plot_1.png')

    return fig

fig = make_plot_1()

Is this the best way to structure such code, take a matplotlib Figure and subplot rect as input, or

  • would it be better to pass a dummy Axes and then replace this somehow with a WCSAxes?
  • not pass anything in, but let plot_ax_1 create an Axes from scratch (possible without a Figure?) and then the Figure is created and the subplots placed later?

@astrofrog
Copy link
Member

@cdeil - just to check, is this something you can do with WCSAxes? For instance:

import matplotlib.pyplot as plt

def plot_ax_1(fig, rect):
    ax = fig.add_axes(rect, projection=WCS(...))
    ax.plot([1,2,3], [2,3,3], color='blue')

def plot_ax_2(fig, rect):
    ax = fig.add_axes(rect, projection=WCS(...))
    ax.plot([1,2,3], [2,3,3], color='red')

def make_plot_1():
    fig = plt.figure(figsize=(10, 10))
    ax1 = plot_ax_1(fig, rect=[0.1, 0.2, 0.3, 0.4])
    ax2 = plot_ax_2(fig, rect=[0.5, 0.6, 0.1, 0.2])
    fig.savefig('/tmp/plot_1.png')

    return fig

fig = make_plot_1()

I'm still trying to figure out where to draw the line between WCSAxes and APLpy... and I need to understand the various use cases better. You should be able to do anything with WCSAxes but it will be a little more manual in some cases. For what you want to do here it seems you want to be close to the Matplotlib API so APLpy doesn't seem appropriate.

@cdeil
Copy link
Contributor Author

cdeil commented Mar 17, 2015

@astrofrog – Here's an example of what I want to do:
http://nbviewer.ipython.org/gist/cdeil/3d6612a98aaf986cf60a

Show the same image twice for different zoomed in regions.
At the moment I'm trying with APLPy, because I wasn't sure how to to recenter with wcsaxes.

I would like to have the two panels have the same height ... do you know how I can prevent FITSFigure.add_colorbar from reducing the height of the image?

@astrofrog
Copy link
Member

@cdeil - for WCSAxes you can just use set_xlim and set_ylim giving it pixel coordinates, and there is no way to zoom in in world coordinates (yet).

@keflavich
Copy link
Member

@cdeil @astrofrog for the colorbar issue, see #119 (which is about colorbars & resizing but doesn't say so in the title)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants