美文网首页
2018-08-30 How to set font size

2018-08-30 How to set font size

作者: 3bb2588f1d48 | 来源:发表于2018-08-31 05:17 被阅读26次

These two blogs are very useful:
[CSDN] https://blog.csdn.net/hqhc9747/article/details/80151062
[Matplotlib_tutorial] https://matplotlib.org/users/pyplot_tutorial.html

Here I take the codes for plotting dispersion curves as an example:
Figure:


Rayleigh_dispersion.png

[path] 10.2.12.10: /home/dabo/work/tianjinexplosion/inversion/plot_disp_R.py

coding:utf-8

import matplotlib.pyplot as plt
import matplotlib as mpl
import numpy as np
from matplotlib.font_manager import FontProperties
import matplotlib as mpl
mpl.rcParams['font.family'] = 'sans-serif'
mpl.rcParams['font.sans-serif'] = 'NSimSun,Times New Roman'

plt.figure(figsize=(14,10)) # set figure size
ax=plt.gca()
ax.set_xscale('log') # set axis as log
plt.xlim(0.4,7)
plt.xticks(fontsize=20) #set xticks fontsize
plt.yticks(fontsize=20)

a1, a2, a3, a4, a5, x0, y0, z0 = np.loadtxt('tmpdispR0', delimiter=' ', dtype=str, unpack=True) # delimiter: split
plt.xscale('log')

print z.dtype

xx0=x0.astype(np.float)
yy0=y0.astype(np.float)
zz0=z0.astype(np.float)
area0 = (0.015 * np.array(1/zz0) + 0.2)**2
plt.scatter(xx0,yy0,s=area0,label='Observed Dispersion of fundamental Mode',color='green')

b1, b2, b3, b4, b5, x1, y1, z1 = np.loadtxt('tmpdispR1', delimiter=' ', dtype=str, unpack=True)

print z.dtype

xx1=x1.astype(np.float) # astype: transfer string to float64
yy1=y1.astype(np.float)
zz1=z1.astype(np.float)
area1 = (0.015 * np.array(1/zz1) + 0.2)**2
plt.scatter(xx1,yy1,s=area1,label='Observed Dispersion of 1st Higher Mode',color='red')

c1, c2, c3, c4, c5, xf0, yf0, zf0 = np.loadtxt('fitEdispR0', delimiter=' ', dtype=str, unpack=True)
xff0=xf0.astype(np.float)
yff0=yf0.astype(np.float)
plt.plot(xff0,yff0,linewidth=2.0,label='Predicted Dispersion of Fundamental Mode',color='green')
d1, d2, d3, d4, d5, xf1, yf1, zf1 = np.loadtxt('fitEdispR1', delimiter=' ', dtype=str, unpack=True)
xff1=xf1.astype(np.float)
yff1=yf1.astype(np.float)
plt.plot(xff1,yff1,linewidth=2.0,label='Predicted Dispersion of 1st Higher Mode',color='red') # set linewidth, label and color
plt.legend(loc='upper left') # set legend location

plt.xticks([0.4,0.6,0.8,1.0,2.0,3.0,4.0,5.0,6.0,7.0],[0.4,0.6,0.8,1.0,2.0,3.0,4.0,5.0,6.0,7.0])
plt.xlabel('Periods(s)',fontsize=20)
plt.ylabel('Group velocity(km/s)',fontsize=20)

plt.title(u'Rayleigh wave dispersion',fontsize=25)

plt.legend()

plt.savefig('Rayleigh.py.eps') #set output figure type
plt.show()

相关文章

网友评论

      本文标题:2018-08-30 How to set font size

      本文链接:https://www.haomeiwen.com/subject/ypvjwftx.html