0

I only modyfied this basic example a little bit so that the spine color of the color bar would change. Interestingly, only the color of the ticks is changing, but not that of the spine. What am I doing wrong?

import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1 import make_axes_locatable
import numpy as np

fig, ax = plt.subplots()
im = ax.imshow(np.arange(100).reshape((10, 10)))

# create an axes on the right side of ax. The width of cax will be 5%
# of ax and the padding between cax and ax will be fixed at 0.05 inch.
divider = make_axes_locatable(ax)
cax = divider.append_axes("right", size="5%", pad=0.05)

colorbar = fig.colorbar(im, cax=cax)
colorbar.ax.tick_params(axis='both', colors='#f9f2d7')
colorbar.ax.spines['bottom'].set_color('#f9f2d7')
colorbar.ax.spines['top'].set_color('#f9f2d7')
colorbar.ax.spines['right'].set_color('#f9f2d7')
colorbar.ax.spines['left'].set_color('#f9f2d7')

fig.canvas.show()
mapf
  • 1,906
  • 1
  • 14
  • 40

1 Answers1

1

Instead of colorbar.ax.spines ... you can use:

colorbar.outline.set_edgecolor('#f9f2d7')

This applies to all 4 edges/spines of the colorbar.

Toby Petty
  • 4,431
  • 1
  • 17
  • 29
  • Thank you! This works in the example, however, it has no effect in my more complex program and I can't figure out why.. very weird. – mapf Dec 19 '19 at 16:37
  • So when I print out `colorbar.outline.get_edgecolor()` the before and after I change it, the return value also changes from `(0.0, 0.0, 0.0, 1.0)` to `(0.9764705882352941, 0.9490196078431372, 0.8431372549019608, 1.0)` so it does do something, but it doesn't show for some reason.. – mapf Dec 19 '19 at 16:43
  • Ok, just for reference, if you use `im.set_clim()` and then redraw, you also need to reset the edge color, the tick color however remains. Very strange. – mapf Dec 19 '19 at 16:58