python 设置横坐标刻度_python 双误差棒(上下误差棒)主刻度 副刻度
生活随笔
收集整理的這篇文章主要介紹了
python 设置横坐标刻度_python 双误差棒(上下误差棒)主刻度 副刻度
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
直接上代碼:
import sys, platform, os, math import matplotlib from matplotlib import pyplot as plt import numpy as np import camb from camb import model, initialpower from matplotlib.ticker import MultipleLocator,FuncFormatter plt.rcParams['xtick.direction'] = 'in' plt.rcParams['ytick.direction'] = 'in'pars = camb.CAMBparams() pars.set_cosmology(H0=67.5, ombh2=0.022, omch2=0.122, mnu=0.06, omk=0, tau=0.06) pars.InitPower.set_params(As=2e-9, ns=0.965, r=0) pars.set_for_lmax(2500, lens_potential_accuracy=0);results = camb.get_results(pars)powers =results.get_cmb_power_spectra(pars, CMB_unit='muK') totCL=powers['total'] unlensedCL=powers['unlensed_scalar']ls = np.arange(totCL.shape[0])data = np.loadtxt('COM_PowerSpect_CMB-TT-full_R3.01.txt') data_ls = data.T[0]; data_CL = data.T[1] data_error = [data.T[2], data.T[3]]fig,ax=plt.subplots(figsize=(8,4)) lmax = 100; clmax = np.max(data_CL[0:lmax]+data.T[3][0:lmax]) if math.modf(clmax/1000)[0] > 0.5:clmax = (int(clmax//1000)+1)*1000 else:clmax = (int(clmax/1000)+0.5)*1000plt.scatter(ls[2:2501],totCL[:,0][2:2501],color='blue',marker='s',s=5) plt.errorbar(data_ls,data_CL,marker='o',markersize=5,color='magenta',yerr=data_error,fmt='o',ecolor='magenta',elinewidth=1.5,capsize=3,barsabove=True) plt.xlim(1,lmax); plt.ylim(0,clmax) plt.xlabel('$l$'); plt.ylabel('$D_l^{TT}[mu k^2]$') plt.xticks(np.append(np.arange(0,lmax,lmax/5),lmax)); plt.yticks(np.append(np.arange(0,clmax,500),clmax)) ax.xaxis.set_minor_locator(MultipleLocator(lmax/25)); ax.yaxis.set_minor_locator(MultipleLocator(100)) plt.show()說明:
- 兩個數據,一個是從[Planck Legacy Archive(PLA)](https://pla.esac.esa.int/#cosmology)下載了CMB角功率譜(plt.errorbar畫出),另外一個是[CAMB](cmbant/CAMB)理論計算出角功率譜(plt.scatter畫出)。
- 可自動設置主刻度和副刻度,橫坐標主刻度控制在5個,每個主刻度有5個副刻度;縱坐標每500個值一個主刻度,每個主刻度有5個副刻度。
效果圖:
總結
以上是生活随笔為你收集整理的python 设置横坐标刻度_python 双误差棒(上下误差棒)主刻度 副刻度的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Counterpoint 去年第 4 季
- 下一篇: 中核集团三门核电 4 号机组开工,支撑华