Choosing color palettes# Seaborn makes it easy to use colors that are well-suited to the characteristics of your data and your visualization goals. This chapter discusses both the general principles that should guide your choices and the tools in seaborn that help you quickly find the best solution for a given application. General principles for using color in plots# Components of color# Because o
次回:Seabornのコンテキスト見本 - 計算物理屋の研究備忘録 次次回:Seabornの色見本 - 計算物理屋の研究備忘録 Seabornとは matplotlibのグラフのスタイルや配色を見やすくきれいに設定してくれる便利なやつ。基本的にはmatplotlibを使うときにちょっと付け足すだけで使えるのでmatplotlib使いなら簡単。 公式サイト Seaborn: statistical data visualization — seaborn 0.7.1 documentation 現在の最新バージョンは0.7.0 インストールはcondaが使えればcondaコマンドからできる。pipでもできると思う。 スタイル一覧 darkgrid whitegrid dark white ticks ticks despine 使い方 公式サイトのチュートリアルから。 https://web
前回、pickleというオブジェクトを保存する方法を紹介しました。ひょっとして、このpickleを使うとpandasモジュールを使ったデータ処理結果を保存しておいたり、再度読み出すことが速くなるのではないかと思い、リードライトする速度を測ることにしました。 まずは150万行程度のcsvファイルを以下コードで生成します。 def file_write_test(): xy=[] x=np.linspace(-np.pi,np.pi,1500000) for r in x: y=np.sin(r) xy.append([r,y]) wfilename='csv_write.dat' csv_write(wfilename,xy,dialect='comma') return xy
#!/usr/bin/env python # -*- coding: utf-8 -*- def get_tuple(): return ('amedama', 'Japan/Tokyo') def print_name(): name, location = get_tuple() print name if __name__ == '__main__': print_name() print_name() 関数の中で、変数 location の値は代入されるが使われない。使わない変数に名前を割り当てるのはイマイチだ。例えば「この変数、使われてないけどバグじゃないよね?」なんて一瞬でも疑う必要があるならそれはコードリーディングを阻害する原因になるかもしれない。もし賢いエディタを使っているなら「Unused variable」なんて警告を出すかもしれない。 関数の返り値がタプルである以上
アンダースコア"_"の役割 Pythonのサンプルコードを読んでいて、 def __init__(): であったり、 def _variable_hogehoge(x): みたいなアンダースコア二つ又は一つで書かれるのをよく見る。 アンダースコア二つで定義される関数は外部の参照を受けないもの。この場合、アンダースコアで囲う。 アンダースコア一つで定義される関数は参照はできるが、基本的に外部から参照しない ということを慣習化させたものらしい。 ここまでは知っていたが、こんなサンプルコードの一文が _, loss_value = sess.run([train_op,loss]) なんのアンダースコアなのかなーと思い調べてみたところ "Python で使わないタプルの値は “_” (アンダーバー) に代入するというプラクティス" ようは、使わない返り値に変数を割り当てるのはナンセンスだから、ア
Pythonで、既存のクラスにインスタンスメソッドを追加する方法をご紹介します。 既存のクラスにメソッドを追加するには次の手順を踏みます。 まず関数を別途定義してから その関数名をクラスのアトリビュートにする 具体例を見てみます。 # __init__ メソッドだけを備えた Dog クラス class Dog(object): def __init__(self, name): self.name = name # 以下で Dog クラスに count_number というインスタンスメソッドを追加する # 01 まずは関数を定義 def count_number(self): print "%s counts: one! one!" % self.name # 02 定義した関数をクラスのアトリビュートに追加 Dog.count_number = count_number # 結果 ta
Controlling figure aesthetics# Drawing attractive figures is important. When making figures for yourself, as you explore a dataset, it’s nice to have plots that are pleasant to look at. Visualizations are also central to communicating quantitative insights to an audience, and in that setting it’s even more necessary to have figures that catch the attention and draw a viewer in. Matplotlib is highl
seabornはmatplotlibベースの統計データビジュアライゼーションライブラリ。 Seaborn is a Python visualization library based on matplotlib. seaborn: statistical data visualization — seaborn 0.6.0 documentation statisticalと銘打っているだけあって、統計的なデータをプロットするための機能がたくさん用意されているが、普通の折れ線グラフの見た目を良くするためだけにも使える。 import numpy as np import matplotlib.pyplot as plt import seaborn as sns sns.set() sns.set_style("whitegrid", {'grid.linestyle': '--'})
scipyにはstatsという統計関数をまとめたモジュールがあります. statsにはいろいろな統計関数が用意されていますが,APIは統一されていますので,それについてちょっとまとめてみます. どんな統計関数があるの? かなりの種類があり,すべてを書くわけにはいかないので, 公式のリファレンスへのリンクを置いておきます. 連続確率変数 離散確率変数 API 各統計関数は,scipy.stats.hogeとしてアクセスできます. 例えば,正規分布なら,scipy.stats.normです. APIはすべての統計関数で共通なので,以下では正規分布の例を使います. from scipy.stats import norm # 正規分布 rvs (Random variates) 確率変数 x = norm.rvs(loc=0, scale=1, size=1) 期待値loc,標準偏差scaleの
I am trying to start IPython with a non default browser (in my case Firefox) and thought I could replicate the replicate the script given in this blog I am on Windows 7 I put the following code in a file say "module.py" import subprocess subprocess.call("ipython notebook --no-browser", shell=True) subprocess.call([r'C:\Program Files (x86)\Mozilla Firefox\Firefox.exe', '-new-tab', 'http://127.0.0.1
Jupyter Notebookの拡張機能を使ってみる Jupyter Notebook をさらに拡張してくれるIPython-notebook-extensions を使ってみたのでメモ。 環境 Windows 10 conda 4.0.5 Jupyter 4.1.0 IPython-notebook-extensions のインストール 今回は、「IPython-notebook-extensions」をインストールする。 github.com 管理者でコマンドプロンプトを実行して、 文字コードが変わっている場合はchcp を戻しておく。 chcp 932 インストール方法は書いてある通り、pip でできる。 anaconda でインストールしたjupyter にも問題なかった。 pip install https://github.com/ipython-contrib/IPytho
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く