Graphing Charts in Python
Python Charts
Now that the data’s going from right to left as we’d like, let’s ensure that there’s no overlap within the x labels:
Code:
import pandas as pd
df = pd.read_excel('world_population_growth.xlsx').sort_values('Year')
ax = df.plot.bar( 'Year' , 'Population' )
for i, t in enumerate(ax.get_xticklabels()):
if (i % 5) != 0:
t.set_visible(False)
Explanation:
The above code is a Python for loop that pulls the data from the chart's x tick labels (the years in the Excel spreadsheet), and displays one year every 5 years in the chart. If you’d like it to display a data label every 10 years, you can change the “i % 5” to “i % 10”.
-
Add a short summary or a list of helpful resources here.