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

axis labels are wonky in gdp mean exercise #673

Open
alee opened this issue Mar 5, 2024 · 2 comments
Open

axis labels are wonky in gdp mean exercise #673

alee opened this issue Mar 5, 2024 · 2 comments
Labels
good first issue Good issue for first-time contributors help wanted Looking for Contributors type:bug Code included in the lesson needs to be fixed

Comments

@alee
Copy link
Member

alee commented Mar 5, 2024

How could the content be improved?

#670 exposed some issues in the rendering of the comparing data challenge

gdp

Which part of the content does your suggestion apply to?

https://swcarpentry.github.io/python-novice-gapminder/14-looping-data-sets.html#comparing-data

@alee alee added help wanted Looking for Contributors type:bug Code included in the lesson needs to be fixed good first issue Good issue for first-time contributors labels Mar 5, 2024
@georginaalbadri
Copy link

Hello,

Two options depending on the amount of complexity we want to add. The first is just to rotate the xticklabels; this can be added prior to the plt.legend() line (outside of the loop):

# rotate the xticklabels on the plot for better readability
plt.xticks(rotation=90)
# stop the labels being cut off when saving the figure
plt.tight_layout()

rotated_labels

The second, the preferred option for a more presentable graph but likely too complex to include at this point in the tutorial is to split the strings in the xticklabels and keep only the year, since the rest of the label is the same for all the data. Add this prior to the plt.lengend() line (outside of the loop):

# set the x-labels to be the year in the column headings of the dataframe
# get dataframe column headings
headings = dataframe.columns[1:]
# split the strings into two parts on the underscore and get the second part (the year)
years = headings.str.split('_').str.get(1)
# use the years as x-axis labels
ax.set_xticks(range(len(years)))
ax.set_xticklabels(years)
ax.set_xlabel('Year')"

split_labels

I think as this part of the lesson is on looping over the data rather than presentation the rotation is probably sufficient!

@alee
Copy link
Member Author

alee commented Mar 9, 2024

Thanks for sharing @georginaalbadri ! A PR for this would be welcome, but I can also submit one on your behalf next week.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good issue for first-time contributors help wanted Looking for Contributors type:bug Code included in the lesson needs to be fixed
Projects
None yet
Development

No branches or pull requests

2 participants