Last active
March 25, 2023 15:22
-
-
Save felixmon/b094a4a4b24d06a84cf4352b425819bf to your computer and use it in GitHub Desktop.
Display Chinese characters vertically in the right way in Matplotlib
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# use index values, which are all Chinese characteres, as x labels, | |
# but not enought space to display, so we need to display the characters vertically, | |
# not jsut rotate x lables | |
# but to display the characters one at each line. | |
# reference & courtesy: https://blog.csdn.net/ai_clay/article/details/126038824 | |
df_new=df_filtered.index # get the index values from the original df | |
df_new= df_new.map(lambda x: '\n'.join(x)) # one character each line | |
ax.set_xticklabels(df_new.tolist(), rotation=0, verticalalignment='center') ## Set x-axis labels | |
# Show the plot | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment