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

Fontsizes in axes and legend don't get updated #17

Closed
jankaWIS opened this issue Jan 23, 2023 · 9 comments
Closed

Fontsizes in axes and legend don't get updated #17

jankaWIS opened this issue Jan 23, 2023 · 9 comments

Comments

@jankaWIS
Copy link

Hi,
Maybe this is related to #14. How do you change fontsize on x and y axes? Or of a legend? I could not find any reference in the docs.
Doing c.ax("myaxis1").set_xlabel('x', fontsize=font_size) does not change anything.
And using c.ax("myaxis1").legend(fontsize=legend_size) somehow scales the entire box and the line length but not the text size.

font_size=18
legend_size=6


# CanD
a = 6
b = 6
c = Canvas(a, b, "cm")

# set font
c.set_font("Arial", size=10)

c.add_axis("myaxis1", Point(2, 2, "cm"), Point(5.5, 5.5, "cm"))
c.ax("myaxis1").plot([1, 2, 3], [1, 2, 3], label='b')
c.ax("myaxis1").plot([1, 2, 3], [1, 1.5, 2], label='o')
# set labels
c.ax("myaxis1").set_ylabel('y')
c.ax("myaxis1").set_xlabel('x', fontsize=font_size)
#legend
c.ax("myaxis1").legend(fontsize=legend_size)

c.show()

image

Thanks!

@mwshinn
Copy link
Owner

mwshinn commented Jan 23, 2023

Thanks for reporting! Unfortunately to control the sizes you have to add them manually. So yes, the same as #14.

@mwshinn mwshinn closed this as completed Jan 23, 2023
@jankaWIS
Copy link
Author

Sorry, one more question, why do matplotlib global params not affect this? So for example, setting:

plt.rc('xtick', labelsize=font_size)  # fontsize of the tick labels
plt.rc('ytick', labelsize=font_size)  # fontsize of the tick labels
plt.rc('legend', fontsize=legend_size)  # legend fontsize

@mwshinn
Copy link
Owner

mwshinn commented Jan 24, 2023

CanD overrides the global settings. You might be able to change this behaviour for the legend by modifying the "c.localRc" dictionary (for c = Canvas(...)) but I have never tried it. That should act just like matplotlib's plt.RcParams dictionary (the thing the "rc" function modifies).

I forgot to mention, though, for the ticks, you can use c.set_font(size=xxx, ticksize=xxx).

@jankaWIS
Copy link
Author

jankaWIS commented Feb 3, 2023

Can you also set the font specifically for only one axis and not globally? Like is there some c.set_font(size=xxx, ticksize=xxx) for a given axis?

@mwshinn
Copy link
Owner

mwshinn commented Feb 3, 2023

Unfortunately not, it is currently only global.

@jankaWIS
Copy link
Author

jankaWIS commented Dec 4, 2024

Hi @mwshinn , me again, I think it's again related. Say I have two subplots and I want to adjust the font of the y tick labels in only one of them (so global setting is not helpful). I tried this:

c.ax("my_ax").tick_params(axis='y', labelsize=2)

but it has no effect. I tried

for label in c.ax("my_ax").get_yticklabels():
    label.set_fontsize(2)

or

labels = c.ax("my_ax").get_yticklabels()
c.ax("my_ax").set_yticklabels(labels, fontsize=2)

but none of it works. Could you please provide a workaround? Or fix this issue?

Thanks!

@mwshinn
Copy link
Owner

mwshinn commented Dec 4, 2024

Currently you can't do this, but if you would like to, you can comment out the code that sets the fonts on the axis tick labels in the "fix_fonts" function in canvas.py. Then you have to set all the tick sizes/fonts manually.

@jankaWIS
Copy link
Author

jankaWIS commented Dec 4, 2024

Thanks for the tip. Would it be possible to implement it or at least allow some level of customisation (maybe using kwargs)? Because I currently need it in only one place and setting all the rest manually is a bit of an overhead.

@mwshinn
Copy link
Owner

mwshinn commented Dec 4, 2024

If you implement it feel free to submit a PR!

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

2 participants