001: # -*- coding: utf-8 -*-
002: """
003: == startdoc
004: ;;; @(#) pyplotsample.py
005: ;;; 型紙ファイル
006: ;;; (fdefun "forml" "sitelisp.lnk" "my-form.l")
007: ;;; (File "progform.sample.lnk" "pyform.txt")
008: ;;; バッファの実行 C-c k p e
009: ;;; (py-execute-buffer)
010: ;;; (File "./matplotlib.txt")
011: $math
012:
013: $Filename: pyplotsample.py $
014: $Lastupdate: 2018-08-25 17:48:05 $
015:
016: このファイルの漢字コードは utf-8 とします。行末コードは、
017: windows タイプ (crlf) とします。
018:
019: ------------------------------------------------------------
020: * グラフの表示エリア
021:
022: 「データ分析ツール Jupyter 入門」(掌田津耶乃著)の第7章
023: の p.266 に記載されている「リスト7-7」を参考にしています。
024:
025: グラフの縦横の描画範囲は、描かれるグラフの図形を元に自動調整
026: されます。が、表示葉にを手動で指定することも可能です。これに
027: は、axis、xlim、ylim という関数を利用します。
028:
029: axis は、xlim と ylim の両方を指定します。
030:
031: @begin{code}{proglist} -------------------------------------
032: """
033:
034: import numpy as np
035: import matplotlib.pyplot as plt
036:
037: x = np.arange(-2*np.pi, 2*np.pi, 0.1)
038: y0 = np.sin(x)
039: y1 = np.cos(x)
040:
041: plt.plot(x, y0, label='y = sin(x)')
042: plt.plot(x, y1, label='y = cos(x)')
043: plt.legend()
044:
045: plt.title('sample graph')
046: plt.xlabel('degree')
047: plt.ylabel('value')
048:
049: plt.grid(which='both', axis='x', color='#0000ff', alpha=0.25, linestyle='-', linewidth=1)
050:
051: plt.grid(which='major', axis='y', color='#00ff00', alpha=0.5, linestyle=':', linewidth=2)
052:
053: plt.xlim([-7, 7])
054: plt.ylim([-1.5, 1.5])
055: # plt.axis(--7, 7, -1.5, 1.5])
056:
057: plt.show()
058:
059: print(x)
060:
061: """
062: @end{code} -------------------------------------------------
063:
064: == enddoc
065: """