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

Change fontsize of axis labels with plot_spectrum? #101

Open
aidenc02 opened this issue Jul 18, 2024 · 4 comments
Open

Change fontsize of axis labels with plot_spectrum? #101

aidenc02 opened this issue Jul 18, 2024 · 4 comments
Labels
question Further information is requested

Comments

@aidenc02
Copy link

Hi, I was wondering if there is any way to edit the size of axis labels with plot_spectrum? I can't seem to find a way to do it on the docs. Thank you!

@wbalmer
Copy link
Contributor

wbalmer commented Jul 18, 2024

(out of the blue answer from Definitely Not Tomas, but I was looking through the repo just now, and I recently had the same problem as you so I have an answer and might as well respond)

The fontsizes are currently hard coded, so you can either edit the package .py files directly to change them (ctrl+F "fontsize=" and replace), or you can try to postprocess your figures by using plt.gca() and cycling through the axes. Example below for the plot_spectrum output.

spec_plot = plot_spectrum(..., output='myspectrum.png')

axs = specplot.axes

# iterate through all axs, change labels and ticks
for ax in axs:
    for item in ([ax.title, ax.xaxis.label, ax.yaxis.label] +
                 ax.get_xticklabels() + ax.get_yticklabels()):
        item.set_fontsize(12) # 12, or whichever fontsize you now prefer

# you can also change the labels themselves, e.g. here I change capital F to f
axs[0].set_ylabel('$f_\\lambda$ (10$^{-16}$ W m$^{-2}$ µm$^{-1}$)')
axs[1].set_ylabel('$\\Delta$$f_\\lambda$ ($\\sigma$)')

# then save the result using savefig
plt.savefig('myspectrum.png', bbox_inches='tight', dpi=300)

Note that if in plot_spectrum you set output=None, this might not work because when output=None, the function calls plt.show() on line 1484 which wipes the current figure and axes lists. So I end up saving the file twice, the first being the uncorrected one and then overwriting that file with the plt.savefig call.

@tomasstolker
Copy link
Owner

Thanks for opening this issue @aidenc02 and for providing the solution @wbalmer 👍 !

Indeed, as I wanted to limit the number of parameters a bit, the way to do this is through the Matplotlib Figure object that is returned by all the plot functions of species.

Feel free to leave this issue open since it is not really explained in the documentation how to adjust the plot properties, so I think your question will be useful for others as well!

@tomasstolker tomasstolker added the question Further information is requested label Jul 19, 2024
@aidenc02
Copy link
Author

@tomasstolker @wbalmer Okay great, thanks so much both of you!

@tomasstolker
Copy link
Owner

To make this more straightforward, I have added the font_size parameter to plot_spectrum. This is a dictionary in which the various font sizes can be set, e.g. font_size={'xlabel': 10., 'xlabel': 8., 'title': 12., 'legend': 9.}. The legend font size is best set with the legend parameter though. Tick font sizes can not be set but could be added later. The update can be pulled from Github.

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

No branches or pull requests

3 participants