gpt4 book ai didi

python - 渐变面色 matplotlib 条形图

转载 作者:太空狗 更新时间:2023-10-30 02:23:15 25 4
gpt4 key购买 nike

如何向条形图中添加渐变 facecolor?我想知道如何将简单的单色渐变用于复杂的多色渐变。下面是一些示例代码:

import numpy as np
import matplotlib.pyplot as plt

plt.figure(figsize=(1,5))
plt.axis([0,1,-50,200])
plt.xticks([])
plt.yticks([-40,180])
plt.bar(left=0, width=1, bottom=-40, height=220, color='r')
plt.subplots_adjust(left=0.4, right=0.8)
plt.savefig("test.png")

最佳答案

import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt

# http://matplotlib.sourceforge.net/examples/api/colorbar_only.html

fig=plt.figure(figsize=(1,5))
ax=fig.add_subplot(111)
ax.axis([0,1,-50,200])
cmap = mpl.cm.jet
norm = mpl.colors.Normalize(vmin=-40, vmax=180)
cb1 = mpl.colorbar.ColorbarBase(ax, cmap=cmap,
orientation='vertical',
norm=norm,
ticks=[-40,180]
)

plt.subplots_adjust(left=0.4, right=0.8)
plt.show()

enter image description here

关于python - 渐变面色 matplotlib 条形图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5296335/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com