1 回答

TA貢獻1847條經驗 獲得超7個贊
您使用的是線性范數,其中pof
值彼此非常接近。使用LogNorm會有所幫助??潭雀袷交绦蚩梢哉{整以按其格式顯示值**6
。
下面的代碼稍微移動了四個函數,因為使用示例中的代碼,所有繪圖似乎都是一致的。至少當我使用類似m=2
(m
代碼中未定義)的東西時。
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import colors as mcolors
from matplotlib import ticker as mticker
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 = mcolors.LogNorm(vmin=np.min(pof6), vmax=np.max(pof6))? # colourbar max and min values
s_m = plt.cm.ScalarMappable(cmap='jet', norm=norm)
s_m.set_array([])
m = 2
for t in pof6:
? ? plt.plot(x, b * x / (((a * t * x ** 2 / (m ** 2)) + 1) ** 2) * e + 10*t**(1/6), color=s_m.to_rgba(t))
func = lambda x, pos: "{:g}**6".format(x**(1/6) )
fmt = mticker.FuncFormatter(func)
c_bar = plt.colorbar(s_m, format=fmt, ticks=pof6)
c_bar.set_label(r'T(K)')
# plt.legend() # there are no labels set, so a default legend can't be created
plt.xlabel('y=E/T')
plt.ylabel('$f_{ν_s}$')
plt.show()
如果您想要圖例,則需要為每條曲線添加標簽,例如:
for t in pof6:
? ? plt.plot(x, b * x / (((a * t * x ** 2 / (m ** 2)) + 1) ** 2) * e, color=s_m.to_rgba(t),
? ? ? ? ? ? ?label=f'$t = {t**(1/6):g}^6$')
plt.legend()
添加回答
舉報