Last active
November 2, 2017 20:24
-
-
Save erikaris/1ff74feca7dcda74885c8a3d977cecee to your computer and use it in GitHub Desktop.
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
# adjust the x-axis labels | |
# step 1: get the x-axis instance. | |
# we can do various things on x-axis instance such as axis.get_ticklabels. | |
# explore other things that we can do on x-axis: https://matplotlib.org/devdocs/api/axis_api.html | |
ax = plt.gca().get_xaxis() | |
# ax2 = plt.gca().xaxis | |
# print(ax) | |
# print(ax2) | |
# step 2: get the ticklabels of the Xaxix | |
# ax.get_ticklabels returns the x tick labels as a list of Text instances. | |
# iterate over each text instance and rotate it | |
# see other things that you can do on Text here: https://matplotlib.org/devdocs/api/text_api.html#matplotlib.text.Text | |
for item in ax.get_ticklabels(): | |
item.set_rotation(45) | |
# step 3: slide up the subplot of 0.25 so that it does not run off the image | |
plt.subplots_adjust(bottom=0.25) | |
# step 4: | |
ax = plt.gca() | |
ax.set_xlabel('Date') | |
ax.set_ylabel('Units') | |
# ax.set_title('Exponential vs. Linear performance') | |
ax.set_title("Exponential ($x^2$) vs. Linear ($x$) performance") | |
# summary of the steps: | |
# axes --> axis --> get_ticklabels() --> rotate the text --> adjust subplot |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment