2018-01-21から1日間の記事一覧

matplotlib / pyplot / 何か図形を描く Polygon(), Circle()

線を描くときはたとえば下のようにする。 import matplotlib.pyplot as plt ax = plt.gca() ax.set_aspect("equal") line = plt.Polygon(((0,0), (5,5), (0,10)), closed=False, fill=False, color="r", linewidth=5) ax.add_patch(line) plt.axis("scaled")…

matplotlib / pyplot / グラフを描く plot()

import matplotlib.pyplot as plt def drawGraph(xList, yList, marker): plt.plot(xList, yList, marker=marker) plt.show() xList = range(-10, 10+1) yList = [x**2 for x in xList] drawGraph(xList, yList, "o")

matplotlib / pylab / グラフを描く plot() / y 軸の値だけ与えた場合

y 軸の値だけ与えた場合は x 軸には y リストのインデックスが使われる。 from pylab import plot, show yList = [50,40,30,20,10,0] plot(yList, marker="o") show() from pylab import plot, show yList = [50,40,30,20,10,0] # x 軸を 0 から始めたくない…

matplotlib / pylab / グラフを描く plot() / マーカーを描く

from pylab import plot, show xList = [x for x in range(-5, 5+1)] yList0 = [x**2 for x in xList] yList1 = [x for x in xList] plot(xList, yList0, "o") # マーカーだけ描く。 plot(xList, yList1, marker="x") # マーカーと線と両方描く。 show()

matplotlib / pylab / グラフを描く plot()

from pylab import plot, show xList = [x for x in range(-5, 5+1)] yList = [x**2 for x in xList] plot(xList, yList) show()