2015-10-09から1日間の記事一覧

<Python, iPython> %alias_magic をstartupに設定

マジックコマンドのエイリアス%alias_magicをスタートアップstartupに設定する。 ~/.ipython/profile_default/startup/00-first.pyに次の呪文を書き込む。 from IPython import get_ipython mgc = get_ipython().magic mgc('%alias_magic h history') stacko…

<Python, iPython> shellのaliasの設定

ipython上でのシェルコマンドshell commandのエイリアスaliasの設定方法。 まずは、次のコマンド実施。 そうするとホーム/home/hage/.ipython/profile_default/以下に下記ファイルができる。 [1:hage@hoge~]> ipython profile create [ProfileCreate] Genera…

<Python> 桁を合わせるには。。。

桁を合わせる方法。format In [7]: '{0:04d}'.format(5) Out[7]: '0005' In [8]: '{0:10d}'.format(5) Out[8]: ' 5' In [9]: '{0:010d}'.format(5) Out[9]: '0000000005' ここで教えてもらいました。 format関数による文字列フォーマット(新しい形式) » Py…

<Python, matplotlib, pyplot> Figureを作りすぎで怒られた場合。

fig, ax =plt.subplots()をループするスクリプトを作ったら、次のエラーで怒られた。 /hoge/python/lib/python3.4/site-packages/matplotlib/pyplot.py:424: RuntimeWarning: More than 20 figures have been opened. Figures created through the pyplot in…

<Python, matplotlib, pyplot> 横軸、縦軸を調整する。

グラフの横軸、縦軸を調整する。 例えば、大きすぎる範囲なので、特定範囲を見せたい時とか、 pyplotの関数、xlim()とylim()を使う。 axの時は、set_xlim()らしい。 In [17]: import matplotlib.pyplot as plt ...: ...: x = range(1,20) ...: y = range(1,2…

<Python, seaborn, matplotlib> 散布図の各要素に文字を付ける(seabornの場合)。

seabornの場合。 In [1]: import seaborn as sns In [2]: import pandas as pd In [3]: df = pd.DataFrame({'X':[1,2,3],'Y':[1,2,3],'A':['a','b','c']}) In [4]: g = sns.lmplot('X','Y',data=df) ...: for k, v in df.iterrows(): ...: g.ax.annotate(v['…