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

[Bug]: wrong text alignment in svg export #20784

Closed
baloe opened this issue Aug 2, 2021 · 2 comments
Closed

[Bug]: wrong text alignment in svg export #20784

baloe opened this issue Aug 2, 2021 · 2 comments

Comments

@baloe
Copy link

baloe commented Aug 2, 2021

Bug summary

When exporting a figure to svg, for rotation=90 text is always left-alignment, no matter how va and ha are actually set.

Code for reproduction

import matplotlib.pyplot as plt

fig,ax = plt.subplots()
for va in ['bottom','top']:
    for ha in ['left','right']:
        ax.annotate( f"{ha}+{va}",
                     xy=(1,0.5), xycoords='data',
                     va=va, ha=ha )
        ax.annotate( f"{ha}+{va}",
                     xy=(0.5,1.0), xycoords='data',
                     rotation=90,
                     va=va, ha=ha )

from matplotlib import rcParams
rcParams['svg.fonttype'] = 'none'
fig.savefig('figure.svg', format='svg')

Actual outcome

(the code produces figure.svg which I cannot upload, because the type is not supported)

Here I open the .svg file in inkscape to illustrate the outcome:
observed

Expected outcome

This is the alignment that I intend to achieve, but which seems to be impossible to produce:

expected

Operating system

Ubuntu 20.04

Matplotlib Version

3.3.2

Matplotlib Backend

Qt5Agg

Python version

3.8.6

Jupyter version

No response

Other libraries

No response

Installation

conda

Conda channel

conda-forge

@QuLogic
Copy link
Member

QuLogic commented Aug 6, 2021

I think what you want is to set the Text rotation mode to 'anchor':

        ax.annotate(f"{ha}+{va}",
                    xy=(0.5, 1.0), xycoords='data',
                    rotation=90, rotation_mode='anchor',
                    va=va, ha=ha)

@baloe
Copy link
Author

baloe commented Aug 9, 2021

I think what you want is to set the Text rotation mode to 'anchor':

        ax.annotate(f"{ha}+{va}",
                    xy=(0.5, 1.0), xycoords='data',
                    rotation=90, rotation_mode='anchor',
                    va=va, ha=ha)

You are right, rotation_mode='anchor' is what I need(ed). Thank you for pointing that out,
and sorry for the noise!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants