python 画图设置横纵坐标_Python输出高质量论文图片
科研至今十年有余,一直使用MATLAB作圖,但是一直覺得MATLAB的線條圖的不夠優(yōu)美,特別是線型的短板極大的限制了作圖的靈活性。
MATLAB只有默認(rèn)的四種線型,而且輸出效果比較呆板。最近在一篇文章的寫作中,一個五種工況的圖頻繁出現(xiàn),既不想改變線寬,也不想使用標(biāo)記。偶聞Python的作圖效果也極其強大,因此抽出一點時間練習(xí)了一下,果然功能強大,而且效果極佳。
代碼和出圖效果如下:
import matplotlib.pyplot as plt #調(diào)用matplotlib
plt.rc('font',family='Times New Roman')? #定義字體
plt.figure(figsize=(7,5.5))? ? #設(shè)置圖片大小
font1 = {'family' : 'Times New Roman',
'weight' : 'normal',
'size'? ?: 16,
}
import numpy as np? ? ? #畫圖過程中會使用numpy
x=np.linspace(0,1,51)? #定義x數(shù)據(jù)范圍
filename = 'data.txt'? #數(shù)據(jù)存在txt文件中,5列
Y1,Y2,Y3,Y4,Y5 = [],[],[],[],[]? #讀入數(shù)據(jù)
with open(filename, 'r') as f:#1
? ? lines = f.readlines()#2
? ? for line in lines:#3
? ? ? ? value = [float(s) for s in line.split()]#4
? ? ? ? Y1.append(value[0])?
? ? ? ? Y2.append(value[1])?
? ? ? ? Y3.append(value[2])?
? ? ? ? Y4.append(value[3])?
? ? ? ? Y5.append(value[4])? ?#至此,數(shù)據(jù)儲存完畢
plt.xticks(fontsize=14)? ? ? ?#設(shè)置坐標(biāo)軸刻度字號
plt.yticks(fontsize=14)
plt.plot(x,Y1,linewidth=2,color='r')? ? #畫圖,第一條線,線寬為2,顏色用color設(shè)置
plt.plot(x,Y2,'-.',linewidth=2)
plt.plot(x,Y3,'--',linewidth=2)
plt.plot(x,Y4,':',linewidth=2)
plt.plot(x,Y5,dashes=[8, 3],linewidth=2) #畫圖,第五條線,線型通過[8,3]修改
plt.ylim(-0.001,0.01)? ? ? ? ? ? ? ? ? ? ?#縱坐標(biāo)范圍
plt.xlim(0,0.65)? ? ? ? ? ? ? ? ? ? ? ? ? #橫坐標(biāo)范圍
plt.title(r"$\beta_x=\beta_y=0.05$",font1) #標(biāo)題
plt.xlabel("Wave number q",font1)? ? ? ? ? #x軸名稱
plt.ylabel(r"Growth rate $\sigma$(q)",font1)? ? #y軸名稱
plt.legend([r"$\beta_i=0$",r"$\beta_i=0.025$",r"$\beta_i=0.05$",r"$\beta_i=0.075$",r"$\beta_i=0.1$"],fontsize=14,edgecolor="black") #設(shè)置標(biāo)注
foo_fig=plt.gcf()
foo_fig.savefig('figure1.eps',format='eps',dpi=1000)? #存儲為eps格式,分辨率100dpi
plt.show()
總結(jié)
以上是生活随笔為你收集整理的python 画图设置横纵坐标_Python输出高质量论文图片的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: android app.build文件_
- 下一篇: 历史快照_实用脚本--合理估算oracl