亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在顏色條上均勻分布刻度?

如何在顏色條上均勻分布刻度?

繁星coding 2023-07-18 17:42:35
我一直在嘗試在顏色欄中繪制一些均勻間隔的刻度線,但到目前為止,我的結果總是給我一個顏色條,刻度線之間的距離與其值成正比,如下圖所示:import numpy as npimport matplotlibimport matplotlib as pltT= [0.01, 0.02, 0.03, 0.04] #values for the colourbar to use in equation in for loopx=np.linspace[0, 8, 100]e=1/(np.exp(x)+1)? ? ? ?#factor used in equation dependent on the x-axis valuesa=6.4*10**(-9)? ? ? ? ?b= 1.51? ? ? ? ? ? ? ? ? # constants for the equationpof6= [number **6 for number in T]norm = matplotlib.colors.Normalize(vmin=np.min(pof6), vmax=np.max(pof6))? #colourbar max and min valuesc_m = matplotlib.cm.cools_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 equationfor 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()我嘗試應用網站上建議的一些解決方案,例如將自定義刻度標簽均勻地分布在顏色條上,但尚未成功。
查看完整描述

1 回答

?
aluckdog

TA貢獻1847條經驗 獲得超7個贊

您使用的是線性范數,其中pof值彼此非常接近。使用LogNorm會有所幫助??潭雀袷交绦蚩梢哉{整以按其格式顯示值**6。

下面的代碼稍微移動了四個函數,因為使用示例中的代碼,所有繪圖似乎都是一致的。至少當我使用類似m=2m代碼中未定義)的東西時。

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()

http://img3.sycdn.imooc.com/64b65ecf00015e6609180429.jpg

如果您想要圖例,則需要為每條曲線添加標簽,例如:


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()


查看完整回答
反對 回復 2023-07-18
  • 1 回答
  • 0 關注
  • 198 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號