1
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Pythonでよく忘れることまとめ

Last updated at Posted at 2019-01-21

目的

Pythonを天文科学計算データの解析として使っている。
色々なことをよく忘れるので、特によく忘れることをメモしておく

IDLのデータをscipyで読み込む

天文コミュニティではいまだにIDLを使って解析している人が多くIDLでデータを渡されることが多い。

a = findgen(100)
b = findgen(200)
save,'test.sav',a,b

とIDLでやるとa, bという配列がtest.savというファイルに保存される

import scipy.io as sio
d = sio.readsav('test.sav')

このようにすると、dという辞書型にデータが格納される。d['a'], d['b']というデータを見ることができる。

軸の表記を消す

tick_paramsを使う。

import matplotlib.pyplot as plt

####
# something
####

plt.tick_params(labelleft=False)

tick_paramsの中のオプション
label* (*=left, right, top, bottom)で字を消す
目盛りを消したい時は、labelをつけない。つまりplt.tick_params(left=False)などとする。
axesインスタンスでも使い方は同じ。つまり

import matplotlib.pyplot as plt
fig = plt.figure(1)
ax = fig.add_subplot(111)
ax.tick_params(labelleft=False)

とすることができる。

ファイルやディレクトリの有無を調べる

import os
os.path.exists('ファイル名')

縦横比を揃える

二次元コンターを現実の座標に対して、おこなう場合。縦横比をスケールを反映したものにしたい時がある。そのための対策

axesインスタンスを使う場合

import matplotlib.pyplot as plt

fig = plt.figure(1)
ax = fig.add_subplot(111,aspect='equal')

とする。axesインスタンスを使わない場合

plt.gca().set_aspect('equal')

とする。

1
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?