APLpy/matplotlib: Coordinate grid alpha levels for EPS quality figure

2024/10/11 17:26:58

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!

Answer

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.

https://en.xdnf.cn/q/118297.html

Related Q&A

How to extract word frequency from document-term matrix?

I am doing LDA analysis with Python. And I used the following code to create a document-term matrixcorpus = [dictionary.doc2bow(text) for text in texts].Is there any easy ways to count the word frequen…

Remove only overlapping ticks in subplots grid

I have created a subplots grid without any spaces between the subplots, with shared x,y-axes. I only show the ticks and labels for the outer subplots. The problem is that the tick numbers overlap at th…

how to start a thread when django runserver?

I want to start a thread when django project runserver successfully. where can I put the create-thread-and-start code? Is there any hook for the django runserver?

pandas groupby plot values

I have a pandas dataframe that looks like this:**real I SI weights**0 1 3 0.3 0 2 4 0.20 1 3 0.50 1 5 0.51 2 5 0.3…

Any python module for customized BNF parser?

friends.I have a make-like style file needed to be parsed. The grammar is something like:samtools=/path/to/samtools picard=/path/to/picardtask1: des: descriptionpath: /path/to/task1para: [$global.samto…

How to draw an histogram with multiple categories in python

I am a freshman in python, and I have a problem of how to draw a histogram in python.First of all, I have ten intervals that are divided evenly according to the length of flowers petal, from min to max…

Turtle in Tkinter creating multiple windows

I am attempting to create a quick turtle display using Tkinter, but some odd things are happening.First two turtle windows are being created, (one blank, one with the turtles), secondly, any attempt of…

Array tkinter Entry to Label

Hey Guys I am beginner and working on Project Linear and Binary search GUI application using Tkinter, I want to add multiple Entry boxes values to label and in an array here, I tried but its not workin…

Grid search and cross validation SVM

i am implementing svm using best parameter of grid search on 10fold cross validation and i need to understand prediction results why are different i got two accuracy results testing on training set not…

Accessing dynamically created tkinter widgets

I am trying to make a GUI where the quantity of tkinter entries is decided by the user.My Code:from tkinter import*root = Tk()def createEntries(quantity):for num in range(quantity):usrInput = Entry(roo…