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

adjustText doesn't work with pie chart? #98

Open
taikutsu91 opened this issue Jun 5, 2020 · 3 comments
Open

adjustText doesn't work with pie chart? #98

taikutsu91 opened this issue Jun 5, 2020 · 3 comments

Comments

@taikutsu91
Copy link

I'm getting the error: AttributeError: 'tuple' object has no attribute 'get_position'
Take a look at example page and I did not see any example with pie chart and make me wonder if it does work with pie.

@taikutsu91
Copy link
Author

Here's an example code:

import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
from adjustText import adjust_text

df = pd.DataFrame({'A': np.linspace(0, 1, 10), 'B': np.linspace(0, 2, 10), 'C': np.linspace(0, 3, 10)})

text = []
fig, axes = plt.subplots(nrows=1, ncols=3, figsize=(12,10))
for ax, col in zip(axes.flat, df.columns):
    text.append(ax.pie(df[col], labels=df.index, autopct='%.2f%%'))
    ax.set(ylabel='', title=col, aspect='equal')
adjust_text(text)

@Phlya
Copy link
Owner

Phlya commented Jun 6, 2020

I've never worked with pie charts... Is there a way to get the text objects that are created for labeling the sectors?

@y9c
Copy link

y9c commented Dec 12, 2022

You should add text objects rather than pie chart into the text list.

_, _, text = ax.Pie(df[col], labels=df.index, autopct='%.2f%%')
adjust_text(text)

will work.

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

3 participants