简体   繁体   中英

Change Scaling/Units of Colorbar in Matplotlib

I am plotting several FITS images along with a colorbar alongside them. I am mainly using Aplpy to plot the images, including the colorbar. As far as I understand, Aplpy does use/rely on matplotlib for its plotting mechanisms, so if there is a way to do what I want in either Aplpy or Matplotlib I think that should work.

The default units of the images are in Jy (an astronomical unit). But the values are all quite small, to where the max is generally 0.01 Jy. When I show a colorbar, the tick labels are in corresponding units and have lots of zeros and take up too much room.

Is there any way I can have the colorbar's units display as mJy (1/1000 of a Jy)?

For example, the ticks are currently: 0.000, 0.002, 0.004, ... I want them to be: 0, 2, 4, ...

The solution could be to either scale the FITS image itself, or adjust the colorbar in some way. Either way, I don't know how to do either...

Thanks in advance.

I guess there are a lot of options. One of them would be to supply a FuncFormatter to the colorbar,

func = lambda x,pos: "{:g}".format(x*1000)
fmt = matplotlib.ticker.FuncFormatter(func)

plt.colorbar(..., format=fmt)

Now I don't know what Aplpy returns, and the question doesn't show any code, so I cannot provide a working solution for that specific case.

The quick and dirty workaround that I came up with:

  1. Make a copy of the original FITS image
  2. Edit the header of the copied image to change the usual BSCALE= 1.0 to BSCALE= 1000.0 (I've used edhead from WCStools to manually edit the header)
  3. Use the image with the edited header as the input for APLpy

The result is the image plotted in the units of mJy instead of Jy.

It would be great to have a proper solution for this, ideally within APLpy. Thanks for asking the exact question I am stuck with right now!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM