Skip to content

colorbar set_ticklabels - text properties not working #20296

Closed

Description

@trafra99

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!

Activity

  1. changed the title [-]set_ticklabels - text properties not working[/-] [+]colorbar set_ticklabels - text properties not working[/+] on May 24, 2021
  2. jklymak commented on May 24, 2021

    @jklymak
    Member

    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?

  3. trafra99 commented on May 24, 2021

    @trafra99
    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.

  4. added this to the v3.5.0 milestone on Jul 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions