adjustText icon indicating copy to clipboard operation
adjustText copied to clipboard

adjustText doesn't work with pie chart?

Open taikutsu91 opened this issue 5 years ago • 3 comments

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 avatar Jun 05 '20 00:06 taikutsu91

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)

taikutsu91 avatar Jun 05 '20 02:06 taikutsu91

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

Phlya avatar Jun 06 '20 09:06 Phlya

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.

y9c avatar Dec 12 '22 02:12 y9c