You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
colorbar set_ticklabels - text properties not working #20296
Unable to set label color or other text properties
Code for reproduction
from mpl_toolkits.axes_grid1.inset_locator import inset_axes
fig, ax = plt.subplots(figsize=(5,6),dpi=200)
#hiding the axis numbers
ax.axes.xaxis.set_visible(False)
ax.axes.yaxis.set_visible(False)
#setting the axis dimensions
ax.set_xlim((-250, 250))
ax.set_ylim((422.5, -47.5))
#setting the background color as black ('k') for a better visualization
ax.set_facecolor('k')
fig.set_facecolor('k')
cbaxes = inset_axes(ax, width="5%",
height="50%",
loc='lower left',
bbox_to_anchor=(.7, 0.07, 5, .08),
bbox_transform=ax.transAxes,
borderpad=0,
)
bar_palette = mpl.cm.inferno
bar = mpl.colorbar.ColorbarBase(cbaxes, cmap=bar_palette, orientation='horizontal')
# creating ticks
bar.set_ticks([0,1])
bar.set_ticklabels(ticklabels=['Low', 'High'], color='white')
Actual outcome
TypeError: set_ticklabels() got an unexpected keyword argument 'color'
Expected outcome
I need the labels to be white because the background is black IMPORTANT
If you put 'white' instead of 'k' in ax.set_facecolor('k') and remove color='white' from bar.set_ticklabels
you can see that the labels are properly created, but they are black and apparently there is no way to make them
change.
Yes, set_ticklabels should probably pass kwargs down to the base axes. #20054 is meant to make this easier, though this particular case has not been addressed yet.
In the meantime, you can do bar.ax.xaxis.set_ticklabels(...) and it will work as you expect.
Yes, set_ticklabels should probably pass kwargs down to the base axes. #20054 is meant to make this easier, though this particular case has not been addressed yet.
In the meantime, you can do bar.ax.xaxis.set_ticklabels(...) and it will work as you expect.
Activity
[-]set_ticklabels - text properties not working[/-][+]colorbar set_ticklabels - text properties not working[/+]jklymak commentedon May 24, 2021
Yes,
set_ticklabelsshould probably pass kwargs down to the base axes. #20054 is meant to make this easier, though this particular case has not been addressed yet.In the meantime, you can do
bar.ax.xaxis.set_ticklabels(...)and it will work as you expect.As an aside, you might consider the core:
though perhaps you do not have a mappable?
trafra99 commentedon May 24, 2021
Thanks for the reply! Unfortunately I do not have a mappable, I'll stick to your solution, it works as a charm.