APLpy/matplotlib: Coordinate grid alpha levels for

2019-06-11 01:42发布

问题:

In the normal matplotlib axes class, it is possible to set gridlines to have a certain transparency (alpha level). I'm attempting to utilise this with the APLpy package using the following:

fig = pyplot.figure(figsize=(18,8))

gridspec_layout = gridspec.GridSpec(1,2)

gridspec_layout1 = gridspec.GridSpecFromSubplotSpec(3, 3, subplot_spec=gridspec_layout[1], hspace=0.0, wspace=0.0)

pyplot_0 = fig.add_subplot(gridspec_layout1[0])
pyplot_1 = fig.add_subplot(gridspec_layout1[1])
pyplot_2 = fig.add_subplot(gridspec_layout1[2])
pyplot_3 = fig.add_subplot(gridspec_layout1[3])
pyplot_4 = fig.add_subplot(gridspec_layout1[4])
pyplot_5 = fig.add_subplot(gridspec_layout1[5])
pyplot_6 = fig.add_subplot(gridspec_layout1[6])
pyplot_7 = fig.add_subplot(gridspec_layout1[7])
pyplot_8 = fig.add_subplot(gridspec_layout1[8])

M33 = aplpy.FITSFigure('myfits.fits', figure=fig, subplot=list(gridspec_layout[0].get_position(fig).bounds), dimensions=[0, 1], slices=[0])

M33 = aplpy.FITSFigure('myfits.fits')
M33.show_grid()
M33.set_grid_alpha(0.1)

pyplot.savefig('myeps.eps', format='eps', dpi=800, clobber=True)

So the transparency is very high and very subtle. However, when I save the plot as an .eps format file, the transparency is lost and my lines are white. In normal matplotlib, I usually use:

ax.set_rasterized(True)

Such that the transparency kind of looks as it should.

I was wondering if there were an equivalent for the aplpy.FITSFigure class...?

Many thanks!

回答1:

In the save function, there is an optional argument, transparent. transparent is set to False by default. If you set it to True, the transparency should be preserved when you save.

So it should be something like:

M33.save(filename, transparent=True, ..)

ETA: In the comments below it was pointed out that the EPS format does not support transparency, so the above code will not work if you're saving in that format.