Remrinのpython攻略日記

python3に入門しました。python3についてあれこれとサンプルコードとか。

matplotlib

matplotlib グラフの設定

matplotlibのグラフの設定について 日本語の表示 日本語を表示する場合は、表示するごとにfontproperties = fpをセットする。 from matplotlib.font_manager import FontProperties fp = FontProperties(fname='C:\WINDOWS\Fonts\msgothic.ttc', size=14) pl…

バーンスレイのシダ

○バーンスレイのシダ 4種類の変換をそれぞれ、85%、7%、7%、1%の確率で選んでいきます。 # -*- coding: utf-8 -*- import numpy as np import matplotlib.pyplot as plt def transform1(p): x, y = p[0], p[1] x1 = 0.85*x + 0.04*y y1 = -0.04*x + 0.85…

matplotlibでアニメーション

matplotlibでアニメーションを作ります。 # -*- coding: utf-8 -*- import matplotlib.pyplot as plt import matplotlib.animation as ani def create_circle(): c1 = plt.Circle((0, 0), 0.5) return c1 def update_radius(i, c1): # i:フレーム番号 plt.cl…

matplotlibで図形

matplotlibで図形を描く方法。 plot()関数が呼ばれると背後でfigure()が呼ばれ、続いてaxes()が呼ばれてfigureの中に軸をつくる。 plot()関数を呼ばずにfigure()やaxes()で図、軸を設定できる。 import matplotlib.pyplot as plt c1 = plt.Circle((0, 0), ra…

matplotlibの色名一覧

matplotlibの色名一覧 この色名一覧はpythonで書かれていて、同じページにコードも載っています。 あとでゆっくりコードを読んでみようと思います。 # coding: utf-8 from __future__ import division import matplotlib.pyplot as plt from matplotlib impo…

matplotlibで散布図

matplotlibで散布図を描く方法について。 Definition : plt.scatter( x, y, # x座標, y座標の配列 s=None, # マーカーのサイズ c=None, # マーカーの色 marker=None, # マーカーの形 cmap=None, # cがfloat型のときのカラーマップ norm=None, # cをfloat型配…

matplotlibで棒グラフ

matplotlibで棒グラフの描き方 Definition : bar(left, #それぞれの棒の左端の配列 height, #高さの配列 width=0.8, #棒の太さ bottom=None, #複数の棒グラフを積み上げるときの土台を示す。 hold=None, # data=None, # **kwargs) ○基本 import matplotlib.p…

matplotlibでヒストグラム

matplotlibでヒストグラムを書く。Definition: hist(x, #データ。yなし。 bins=None, #bin(棒)の数。省略すると10 range=None, #binの表示範囲をタプルで。 normed=False, #Trueとすると正規化(合計値を1とする) weights=None, # cumulative=False, #True:累…

matplotlibで折れ線グラフ

計算結果をビジュアルで見るには、やはりグラフを描くのが一番ですね。 ということで、matplotlibの使い方を簡単に紹介します。 import matplotlib.pyplot as plt listx = [1, 2, 3, 4] listy = [1, 3, 4, 2] plt.plot(listx, listy) たったこれだけで、折れ…