13,024
回編集
(ページの作成:「== 概要 == ここでは、PyQtとMatplotlibを使用して、グラフを表示する方法を記載する。<br> <br><br> == Matplotlibとは == Matplotlibとは、Py…」) |
|||
| 18行目: | 18行目: | ||
<br><br> | <br><br> | ||
== | == Matplotlibで作成するグラフ (1) == | ||
このセクションでは、PyQtとMatplotlibを使用してグラフを表示する。<br> | このセクションでは、PyQtとMatplotlibを使用してグラフを表示する。<br> | ||
[https://pythonspot.com/tag/pyqt5/page/2/ こちらのWebサイト]のチュートリアルにある<u>PyQt5 Matplotlib</u>という箇所とサンプルコードを参考にする。<br> | [https://pythonspot.com/tag/pyqt5/page/2/ こちらのWebサイト]のチュートリアルにある<u>PyQt5 Matplotlib</u>という箇所とサンプルコードを参考にする。<br> | ||
| 27行目: | 27行目: | ||
<br> | <br> | ||
<source lang="python"> | <source lang="python"> | ||
# - * - coding: utf8 - * | |||
import sys | import sys | ||
import random | import random | ||
| 42行目: | 44行目: | ||
def __init__(self): | def __init__(self): | ||
super().__init__() | super().__init__() | ||
self.left = 10 | self.left = 10 | ||
self.top = 10 | self.top = 10 | ||
self.title = | self.title = "PyQt5 matplotlib example - pythonspot.com" | ||
self.width = 640 | self.width = 640 | ||
self.height = 400 | self.height = 400 | ||
| 65行目: | 67行目: | ||
def __init__(self, parent=None, width=5, height=4, dpi=100): | def __init__(self, parent=None, width=5, height=4, dpi=100): | ||
fig = Figure(figsize=(width, height), dpi=dpi) | fig = Figure(figsize=(width, height), dpi=dpi) | ||
self.axes = fig.add_subplot(111) | self.axes = fig.add_subplot(111) | ||
| 78行目: | 80行目: | ||
def plot(self): | def plot(self): | ||
data = [random.random() for i in range(25)] | data = [random.random() for i in range(25)] | ||
ax = self.figure.add_subplot(111) | ax = self.figure.add_subplot(111) | ||
ax.plot(data, 'r-') | ax.plot(data, 'r-') | ||
ax.set_title('PyQt Matplotlib Example') | ax.set_title('PyQt Matplotlib Example') | ||