adjustText
adjustText copied to clipboard
adjustText doesn't work with pie chart?
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.
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)
I've never worked with pie charts... Is there a way to get the text objects that are created for labeling the sectors?
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.