0

Is it possible to change the text color of the cbar legend values ? We want to use a black background but the text is falling away. We use Matplotlib for plotting. We can change the text color of the label, but not of the values.

 cbar = m.colorbar(cs,location='right',pad="10%")
 cbar.set_label('dBZ', color="white")

Thank you in advanced.

Kevin Broeren

user3408380
  • 375
  • 3
  • 5
  • 22

1 Answers1

0

You can change the color of the color bar values using set_yticklabels since they are tick labels for the color bar axis. Here's an example:

import matplotlib.pyplot as plt
from numpy.random import randn

# plot something
fig, ax = plt.subplots()
cax = ax.imshow(randn(100,100))

# create the color bar
cbar = fig.colorbar(cax)
cbar.set_label('dBZ', color = "white")

# update the text 
t = cbar.ax.get_yticklabels();
labels = [item.get_text() for item in t]
cbar.ax.set_yticklabels(labels, color = 'white')
plt.show()

The first answer to this question has an explanation of why you need to do it this way.

color bar with white text for the label and values

Community
  • 1
  • 1
Molly
  • 13,240
  • 4
  • 44
  • 45