Last active
March 21, 2017 16:33
-
-
Save rmania/66b1ca2a60109e705a4ee0f683263580 to your computer and use it in GitHub Desktop.
tricks for manipulating the settings of matplotlib graphs
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
# modify color of yticklabels for the current axes | |
[i.set_color("red") for i in plt.gca().get_yticklabels()] | |
# get all tweakable parameters of 'ytick' etc.. | |
[(param, value) for param, value in plt.rcParams.items() if 'ytick' in param] | |
# get the yticklabel texts | |
[item.get_text() for item in axi.get_yticklabels()] | |
#change label display parameters like fontsize | |
[tick.label.set_fontsize(14) for tick in ax.yaxis.get_major_ticks()] | |
# change xticklabel colors | |
for ticklabel, tickcolor in zip(plt.gca().get_xticklabels(), my_colors): | |
ticklabel.set_color(tickcolor) | |
# color bar yticklabels manipulation | |
cbar.ax.set_yticklabels(['{:.0f}'.format(x) for x in np.arange(cbar_min, cbar_max+cbar_step, cbar_step)], fontsize=16, weight='bold') | |
# For every axis, set the x and y major locator | |
for axi in ax.flat: | |
axi.xaxis.set_major_locator(plt.MaxNLocator(3)) | |
axi.yaxis.set_major_locator(plt.MaxNLocator(3)) | |
# get float of 2 decimals for the xticks | |
['{:,.2f}'.format(x) for x in xticks] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment