Reputation: 1390
I would like to change the width of spines for both axis:
img = np.random.normal(size=(100, 100))
fig, ax = plt.subplots()
cax = ax.imshow(img)
cbar = fig.colorbar(cax, ticks=np.linspace(0, 70, 8))
[i.set_linewidth(3) for i in cbar.ax.spines.itervalues()]
[i.set_linewidth(3) for i in ax.spines.itervalues()]
However, as the result I get the following:
How can I change the length of the spines for the colorer axis?
Upvotes: 5
Views: 10446
Reputation: 339430
You may try to set the frame of the colorbar axes on again, such that the changes to its spines can take an effect.
cbar.ax.set_frame_on(True)
Complete example (only tested with matplotlib 2.0)
import matplotlib.pyplot as plt
import numpy as np
img = np.random.normal(size=(100, 100))
fig, ax = plt.subplots()
im = ax.imshow(img)
cbar = fig.colorbar(im, ticks=np.linspace(0, 70, 8))
cbar.ax.set_frame_on(True)
[i.set_linewidth(3) for i in cbar.ax.spines.itervalues()]
[i.set_linewidth(3) for i in ax.spines.itervalues()]
plt.show()
Upvotes: 3
Reputation: 4627
I would have expected your solution to work but a possible work around is to set axes.linewidth
and remove the set_linewidth(3)
lines
import matplotlib
matplotlib.rcParams['axes.linewidth'] = 3
I figured out this work around by finding this:
edit
Alternatively you can set the outline line width directly:
img = np.random.normal(size=(100, 100))
fig, ax = plt.subplots()
cax = ax.imshow(img)
cbar = fig.colorbar(cax, ticks=np.linspace(0, 70, 8))
cbar.outline.set_linewidth(3)
[i.set_linewidth(3) for i in ax.spines.itervalues()]
Upvotes: 7