我一直在尝试在颜色栏中绘制一些均匀间隔的刻度线,但到目前为止,我的结果总是给我一个颜色条,刻度线之间的距离与其值成正比,如下图所示:
import numpy as np
import matplotlib
import matplotlib as plt
T= [0.01, 0.02, 0.03, 0.04] #values for the colourbar to use in equation in for loop
x=np.linspace[0, 8, 100]
e=1/(np.exp(x)+1) #factor used in equation dependent on the x-axis values
a=6.4*10**(-9)
b= 1.51 # constants for the equation
pof6= [number **6 for number in T]
norm = matplotlib.colors.Normalize(vmin=np.min(pof6), vmax=np.max(pof6)) #colourbar max and min values
c_m = matplotlib.cm.cool
s_m = matplotlib.cm.ScalarMappable(cmap='jet', norm=norm)
s_m.set_array([])
#below is the for loop that uses one value of T at a time, represented as t in the equation
for t in pof6:
plt.plot(x, b*x/(((a*t*x**2/(m**2))+1)**2)*e, color=s_m.to_rgba(t))
func = lambda x,pos: "{:g}".format(x)
fmt = matplotlib.ticker.FuncFormatter(func)
c_bar=plt.colorbar(s_m, format=fmt, ticks=[0.01**6,0.02* 0.03**6, 0.04**6])
plt.legend()
plt.xlabel('y=E/T')
plt.ylabel('$f_{ν_s}$')
c_bar.set_label(r'T(K)')
plt.show()
我尝试应用网站上建议的一些解决方案,例如将自定义刻度标签均匀地分布在颜色条上,但尚未成功。
aluckdog
相关分类