dict 형식 이용하여 변수명 자동 설정하기. [2018.09.13]

Posted by 센큐
2018. 9. 13. 15:56 Mathematica&Python

vars()['name {}'.format(variable)] = 1    #name variable  이라는 variable에 1이 들어간다.

globals()['name {}'.format(variable)] = 2    #name variable  이라는 global variable에 2가 들어간다.



ex)

a=1

vars()['name_{}'.format(a)]=1

print name_a

==> 1 출력.


matplotlib.pyplot 이용하여 그래프 꾸미기 [2018.09.12]

Posted by 센큐
2018. 9. 13. 00:04 Mathematica&Python

fig = matplotlib.pyplot.figure(1)    #figure 1번 생성.

ax = fig.add_subplot(3, 2, 1)    #3행 2열짜리 배열 중 1번째 자리에 ax이라는 subplot을 fig에 생성.

ax.plot(x, y)    #x array, y array 그래프 그리기.

ax.ticklabel_format(style = 'sci', scilimits = (-3, 5), axis='both', useMathText = True)    #'sci'entific notation, 10^(-3)~10^5 이외 구역 적용

ax.tick_params(direction='in')    #ticklabel 그래프 안쪽으로 넣기. (기본은 바깥쪽.)