Matplotlib色轮作为颜色条

时间:2016-08-22 15:27:42

标签: matplotlib colorbar polar-coordinates

有没有办法绘制色轮而不是彩条?我通过

尝试了这篇文章Plot a (polar) color wheel based on a colormap using Python/Matplotlib
import matplotlib
import matplotlib.pyplot as plt
import numpy as np

f = plt.figure(figsize=(10, 8))
ax = f.add_subplot(111)

display_axes = f.add_axes([0.7, 0.75, 0.15, 0.15],
                           projection='polar')

# This is a nasty hack - using the hidden field to multiply the values
# such that 1 become 2*pi this field is supposed to take values 1 or -1
# only!!
display_axes._direction = 2 * np.pi
norm = matplotlib.colors.Normalize(0.0, 2 * np.pi)

# Plot the colorbar onto the polar axis note - use orientation
# horizontal so that the gradient goes around the wheel rather than
# centre out
quant_steps = 2056
cb = matplotlib.colorbar.ColorbarBase(display_axes,
                                      cmap=matplotlib.cm.get_cmap('hsv',
                                                                  quant_steps),
                                      norm=norm,
                                      orientation='horizontal',
                                      )

# aesthetics - get rid of border and axis labels
cb.outline.set_visible(False)
xL = [r'$0$', r'$\frac{\pi}{2}$', r'$\pi$', r'$\frac{3\pi}{2}$']
cb.set_ticks([0, np.pi / 2, np.pi, 3 * np.pi * 0.5])
cb.set_ticklabels(xL)
cb.ax.tick_params(labelsize=22, zorder=10)
# display_axes.set_axis_off()
display_axes.set_rlim([-1, 1])

cb.ax.tick_params(axis='both', which='major', pad=30)

enter image description here

但是,我不能让标签进一步远离方向盘。我认为这是因为代码中存在display_axes._direction hack。我在想是否有更好的方法来实现这一目标。

0 个答案:

没有答案