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

colorbar set_ticklabels - text properties not working #20296

Closed
trafra99 opened this issue May 24, 2021 · 2 comments · Fixed by #20758
Closed

colorbar set_ticklabels - text properties not working #20296

trafra99 opened this issue May 24, 2021 · 2 comments · Fixed by #20758

Comments

@trafra99
Copy link

trafra99 commented May 24, 2021

Bug report

Bug summary

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.

Matplotlib version

  • Operating system: Mac OS Big Sur
  • Matplotlib version: 3.4.0
  • Matplotlib backend : module://ipykernel.pylab.backend_inline
  • Python version: 3.9.2

Thanks to anyone who can help!

@jklymak jklymak changed the title set_ticklabels - text properties not working colorbar set_ticklabels - text properties not working May 24, 2021
@jklymak
Copy link
Member

jklymak commented May 24, 2021

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.

As an aside, you might consider the core:

cbaxes = ax.inset_axes([0.7, -0.075, 0.3, 0.03]) 
bar = fig.colorbar(mappable, cax=cbaxes)

though perhaps you do not have a mappable?

@trafra99
Copy link
Author

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.

As an aside, you might consider the core:

cbaxes = ax.inset_axes([0.7, -0.075, 0.3, 0.03]) 
bar = fig.colorbar(mappable, cax=cbaxes)

though perhaps you do not have a mappable?

Thanks for the reply! Unfortunately I do not have a mappable, I'll stick to your solution, it works as a charm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants