# -*- coding:utf-8 -*- # 2 つのグラフを表示する import numpy import matplotlib.pyplot as plt def f(t): return numpy.exp(-t) * numpy.cos(2 * numpy.pi * t) t1 = numpy.arange(0.0, 5.0, 0.1) t2 = numpy.arange(0.0, 5.0, 0.02) fig = plt.figure(1) # 2 rows, 1 column, first plot plt.subplot(2, 1, 1) plt.plot(t1, f(t1), 'bo', t2, f(t2), 'k') # 2 rows, 1 column, second plot plt.subplot(2, 1, 2) plt.plot(t2, numpy.cos(2 * numpy.pi * t2), 'r--') # png 出力 fig.savefig('test08.png')
4 つ載せる場合
# -*- coding:utf-8 -*- # 4 つのグラフを表示する import numpy import matplotlib.pyplot as plt t1 = numpy.arange(0.0, 1.0, 0.02) fig = plt.figure(1) # 2 rows, 2 column, first plot plt.subplot(2, 2, 1) plt.title('sin()') plt.plot(t1, numpy.sin(2 * numpy.pi * t1), 'k') # 2 rows, 2 column, second plot plt.subplot(2, 2, 2) plt.title('cos()') plt.plot(t1, numpy.cos(2 * numpy.pi * t1), 'r') # 2 rows, 2 column, third plot plt.subplot(2, 2, 3) plt.title('tan()') plt.plot(t1, numpy.tan(2 * numpy.pi * t1), 'b') # 2 rows, 2 column, fourth plot plt.subplot(2, 2, 4) plt.title('log()') plt.plot(t1, numpy.log(t1), 'g') # png 出力 fig.savefig('test09.png')
0 件のコメント:
コメントを投稿