Matplotlib and string formatting

I was working through the ‘Analyze Data With Python Skill Path’.

Lesson: ‘Why data?’ under ‘Introduction to data analysis’; Part: 4/8 :
https://www.codecademy.com/paths/analyze-data-with-python/tracks/ida-1-introduction-to-data-analysis/modules/ida-1-1-why-data-analysis/lessons/day-in-the-life-data-analyst/exercises/matplotlib

In the following code:

#Make a pie chart
plt.pie(survey_results.values,
labels=survey_results.index,
autopct=’%d%%’
)
plt.title(‘Why do citizens visit our website?’)
plt.axis(‘equal’)

Question:
What does autopct = %d%% mean? Why do we write %d%% rather than %d?
What does plt.axis(‘equal’) mean?

Best place to check would be the docs that describes each of these functions-
https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.pie.html#matplotlib.pyplot.pie
https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.axis.html#matplotlib.pyplot.axis
I’d assume the double %% is to escape the character so it actually prints a % symbol.

1 Like