개발 꿀팁/PYTHON

Python 그림 그리기, 점선 그림입니다

Jammie 2022. 12. 15. 14:28
반응형
import matplotlib.pyplot as plt
import matplotlib.pylab as pylab
import scipy.io
import numpy as np
params={
'axes.labelsize': '35', #축 위의 글자입니다.
'xtick.labelsize': '27', #축 범례
'ytick.labelsize': '27', #축 범례
'lines.linewidth':2, #선폭입니다.
'legend.fontsize': '27', # 범례 크기입니다.
'figure.figsize': '12, 9' # set figure size, 가로 12, 세로 9입니다.
}
pylab.rcParams.update(params) #set figure parameter
#그림 라이브러리 업데이트입니다.

#line_styles=['ro-','b^-','gs-','ro--','b^--','gs--'] #set line style

#We give the coordinate date directly to give an example.
x1 = [-20,-15,-10,-5,0,0,5,10,15,20]

y1 = [0,0.04,0.1,0.21,0.39,0.74,0.78,0.80,0.82,0.85]
y2 = [0,0.014,0.03,0.16,0.37,0.78,0.81,0.83,0.86,0.92]
y3 = [0,0.001,0.02,0.14,0.34,0.77,0.82,0.85,0.90,0.96]
y4 = [0,0,0.02,0.12,0.32,0.77,0.83,0.87,0.93,0.98]
y5 = [0,0,0.02,0.11,0.32,0.77,0.82,0.90,0.95,1]


plt.plot(x1,y1,'bo-',label='m=2, p=10%',markersize=20) # in 'bo-', b is blue, o is O marker, - is solid line and so on
plt.plot(x1,y2,'gv-',label='m=4, p=10%',markersize=20)
plt.plot(x1,y3,'ys-',label='m=6, p=10%',markersize=20)
plt.plot(x1,y4,'ch-',label='m=8, p=10%',markersize=20)
plt.plot(x1,y5,'mD-',label='m=10, p=10%',markersize=20)

fig1 = plt.figure(1)
axes = plt.subplot(111)
#코드는 별로 할 말이 없습니다, 여기 plt.subplot(111)이라는 함수만 말씀드리겠습니다.
#plt.subplot(111)과 plt.subplot(1,1,1)은 동등합니다.영역을 1행 1열로 나눈다는 뜻으로, 현재 첫 번째 그림(줄에서 열로 정렬)을 그립니다.
#plt.subplot(211)은 영역을 2행 1열로 나누는 것을 의미하며, 현재 첫 번째 그림(첫 번째 줄, 첫 번째 열)을 그립니다.이와 같이 유추하면 10을 초과하지 않는 한 쉼표를 생략할 수 있습니다.

#axes = plt.gca()
axes.set_xticks([-20,-15,-10,-5,0,5,10,15,20])
axes.set_yticks([0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0])
axes.grid(True) # add grid

plt.legend(loc="lower right") #set legend location
plt.ylabel('Percentage') # set ystick label
plt.xlabel('Difference') # set xstck label

plt.savefig('plot_test1.png',dpi = 1000,bbox_inches='tight')
plt.show()

 

반응형