如何更改matplotlib颜色条的书脊颜色? [英] How can you change the spine color of a matplotlib colorbar?

查看:120
本文介绍了如何更改matplotlib颜色条的书脊颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只修改了这个基本示例颜色栏的书脊颜色将发生变化.有趣的是,只有the的颜色在变化,而脊柱的颜色没有变化.我在做什么错了?

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()

推荐答案

您可以使用:

colorbar.outline.set_edgecolor('#f9f2d7')

这适用于颜色栏的所有4个边缘/书脊.

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

这篇关于如何更改matplotlib颜色条的书脊颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆