如何更改 matplotlib 颜色条的书脊颜色?
How can you change the spine color of a matplotlib colorbar?
我只修改了 this basic example 一点点,这样颜色条的书脊颜色就会改变。
有趣的是,只有蜱的颜色在变化,而脊柱的颜色没有变化。我做错了什么?
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.ax.spines ...
colorbar.outline.set_edgecolor('#f9f2d7')
这适用于所有 4 个 edges/spines 颜色栏。
我只修改了 this basic example 一点点,这样颜色条的书脊颜色就会改变。 有趣的是,只有蜱的颜色在变化,而脊柱的颜色没有变化。我做错了什么?
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.ax.spines ...
colorbar.outline.set_edgecolor('#f9f2d7')
这适用于所有 4 个 edges/spines 颜色栏。