When using PyQtGraph with Python Pyside, pay attention to the order of import

For the time being, save this as im.py and execute it.

from PySide import QtCore, QtGui
import pyqtgraph as pg

class Ui_MainWindow(object): def setupUi(self, MainWindow): MainWindow.setObjectName("MainWindow") self.centralwidget = QtGui.QWidget(MainWindow) self.centralwidget.setObjectName("centralwidget") MainWindow.setCentralWidget(self.centralwidget)

    <span style="color: #008000">self</span><span style="color: #666666">.</span>verticalLayout <span style="color: #666666">=</span> QtGui<span style="color: #666666">.</span>QVBoxLayout(<span style="color: #008000">self</span><span style="color: #666666">.</span>centralwidget)
    <span style="color: #008000">self</span><span style="color: #666666">.</span>verticalLayout<span style="color: #666666">.</span>setObjectName(<span style="color: #BA2121">&quot;verticalLayout&quot;</span>)

    <span style="color: #008000">self</span><span style="color: #666666">.</span>graph01 <span style="color: #666666">=</span> pg<span style="color: #666666">.</span>PlotWidget(<span style="color: #008000">self</span><span style="color: #666666">.</span>centralwidget)
    <span style="color: #008000">self</span><span style="color: #666666">.</span>graph01<span style="color: #666666">.</span>setObjectName(<span style="color: #BA2121">&quot;graph01&quot;</span>)
    <span style="color: #008000">self</span><span style="color: #666666">.</span>verticalLayout<span style="color: #666666">.</span>addWidget(<span style="color: #008000">self</span><span style="color: #666666">.</span>graph01)
    
    <span style="color: #008000">self</span><span style="color: #666666">.</span>psbtn <span style="color: #666666">=</span> QtGui<span style="color: #666666">.</span>QPushButton(<span style="color: #008000">self</span><span style="color: #666666">.</span>centralwidget)
    <span style="color: #008000">self</span><span style="color: #666666">.</span>psbtn<span style="color: #666666">.</span>setObjectName(<span style="color: #BA2121">&quot;psbtn&quot;</span>)
    <span style="color: #008000">self</span><span style="color: #666666">.</span>psbtn<span style="color: #666666">.</span>setText(<span style="color: #BA2121">&quot;Plot&quot;</span>)
    <span style="color: #008000">self</span><span style="color: #666666">.</span>verticalLayout<span style="color: #666666">.</span>addWidget(<span style="color: #008000">self</span><span style="color: #666666">.</span>psbtn)

    QtCore<span style="color: #666666">.</span>QObject<span style="color: #666666">.</span>connect(<span style="color: #008000">self</span><span style="color: #666666">.</span>psbtn, QtCore<span style="color: #666666">.</span>SIGNAL(<span style="color: #BA2121">&quot;clicked()&quot;</span>), <span style="color: #008000">self</span><span style="color: #666666">.</span>plot)
    

<span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">plot</span>(<span style="color: #008000">self</span>):
    frq <span style="color: #666666">=</span> <span style="color: #666666">10.0</span>
    duration <span style="color: #666666">=</span> <span style="color: #666666">1.0</span>
    samples <span style="color: #666666">=</span> <span style="color: #666666">1001</span>
    x <span style="color: #666666">=</span> np<span style="color: #666666">.</span>linspace(<span style="color: #666666">0</span>, duration, samples)
    rad <span style="color: #666666">=</span> np<span style="color: #666666">.</span>linspace(<span style="color: #666666">0</span>, <span style="color: #666666">2</span> <span style="color: #666666">*</span> np<span style="color: #666666">.</span>pi <span style="color: #666666">*</span> frq, samples)
    y <span style="color: #666666">=</span> np<span style="color: #666666">.</span>sin(rad)
    <span style="color: #008000">self</span><span style="color: #666666">.</span>graph01<span style="color: #666666">.</span>plot(x, y)

import sys import numpy as np

pg.setConfigOption('foreground', 'k') pg.setConfigOption('background', 'w')

class ControlMainWindow(QtGui.QMainWindow): def init(self, parent=None): super(ControlMainWindow, self).init(parent) self.ui = Ui_MainWindow() self.ui.setupUi(self)

if name == "main": app = QtGui.QApplication(sys.argv) mySW = ControlMainWindow()#class no instance-ka mySW.show() sys.exit(app.exec_())

Will be like this

Screenshot from 2016-08-22 11-11-38.png

If you swap the first two lines

In other words, in this order

import pyqtgraph as pg
from PySide import QtCore, QtGui
An error occurs. TypeError: arguments did not match any overloaded call: QGraphicsView(QWidget parent=None): argument 1 has unexpected type 'PySide.QtGui.QWidget' QGraphicsView(QGraphicsScene, QWidget parent=None): argument 1 has unexpected type 'PySide.QtGui.QWidget'

The reason was written here

http://www.pyqtgraph.org/documentation/how_to_use.html#pyqt-and-pyside Probably translated.

PyQt and PySide

PyQtGraph supports PyQt and PySide, Python wrappers for two popular QT libraries. Both packages provide almost the same API and functions, but for various reasons, I think you should choose one or the other. When pyqtgraph is first imported, pyqtgraph will automatically determine which library to use with the following check items:

1 If PyQt4 is already imported, use it 2 Otherwise, if PySide is already imported, use it, 3 Otherwise, try to import PyQt4 and 4 If PyQt4 import fails, try importing PySide.

If you have both PyQt4 and PySide libraries installed on your system and want to use pyqtgraph on either side, simply import that library before importing pyqtgraph. please.

import PySide ## this will force pyqtgraph to use PySide instead of PyQt4 import pyqtgraph as pg

The previous error, argument 1 has unexpected type'PySide.QtGui.QWidget'

In the line self.graph01 = pg.PlotWidget (self.centralwidget), pyqtgraph.PlotWidget intended to have something of PyQt in its argument ↓ 'PySide.QtGui.QWidget' has arrived. Argument 1 has an unexpected type'PySide.QtGui.QWidget'. I think that is the state. PyQtGraph A library for plotting in Python. http://www.pyqtgraph.org/

Is Matplotlib useless?

Not bad. Matplotlib is a standard library for plotting in Python. But PyQtGraph is faster. http://yukara-13.hatenablog.com/entry/2013/12/05/025655

PySide and PyQt

If you want to create a GUI using Qt in Python, you can choose between these two. There is a difference between the LGPL and GPL in the license. PySide ・ ・ ・ LGPL. I feel that there is not much information on the net, probably because there are not many people using it. (Approximately 214,000 when searching google) PyQt ・ ・ ・ GPL. Copyleft. I feel that the number of users appears in the search results. (Google search 667,000)

Recommended Posts

When using PyQtGraph with Python Pyside, pay attention to the order of import
How to correctly upgrade the software when building Linux (CentOS) with Vagrant ~ Using the example of upgrading from Python 2.7 to Python 3.6 ~
A memo of misunderstanding when trying to load the entire self-made module with Python3
I tried to find the entropy of the image with python
Try to automate the operation of network devices with Python
Things to keep in mind when using Python with AtCoder
Things to keep in mind when using cgi with python.
List of libraries to install when installing Python using Pyenv
Get the source of the page to load infinitely with python.
How to know the number of GPUs from python ~ Notes on using multiprocessing with pytorch ~
Try to import to the database by manipulating ShapeFile of national land numerical information with Python
[Python] How to import the library
When using MeCab with virtualenv python
Precautions when using six with Python 2.5
I want to output the beginning of the next month with Python
Output the contents of ~ .xlsx in the folder to HTML with Python
From the introduction of JUMAN ++ to morphological analysis of Japanese with Python
I tried to improve the efficiency of daily work with Python
PhytoMine-I tried to get the genetic information of plants with Python
When you want to use multiple versions of the same Python library (virtual environment using venv)
What to do if you get a "Wrong Python Platform" warning when using Python with the NetBeans IDE
How to crop the lower right part of the image with Python OpenCV
Check the existence of the file with python
How to deal with OAuth2 error when using Google APIs from Python
Python Note: When you want to know the attributes of an object
Try to image the elevation data of the Geographical Survey Institute with Python
[Introduction to Python] How to sort the contents of a list efficiently with list sort
Working with OpenStack using the Python SDK
How to deal with SSL error when connecting to S3 with boto of Python
I tried to get the authentication code of Qiita API with Python.
How to deal with the problem that build fails when CI / CD of Python Function with AWS Amplify
I tried to streamline the standard role of new employees with Python
I tried to get the movie information of TMDb API with Python
Get and estimate the shape of the head using Dlib and OpenCV with python
[Introduction to Python] What is the method of repeating with the continue statement?
The road to compiling to Python 3 with Thrift
[Python] I tried to judge the member image of the idol group using Keras
[Circuit x Python] How to find the transfer function of a circuit using Lcapy
Let's simulate the transition of infection rate with respect to population density with python
Execution order when multiple context managers are specified in the Python with statement
Three things I was addicted to when using Python and MySQL with Docker
I tried to easily visualize the tweets of JAWS DAYS 2017 with Python + ELK
[In-Database Python Analysis Tutorial with SQL Server 2017] Step 2: Import data to SQL Server using PowerShell
What you want to memorize with the basic "string manipulation" grammar of python
About the handling of ZIP files including Japanese files when upgrading from Python2 to Python3
Note: How to get the last day of the month with python (added the first day of the month)
I made a script to record the active window using win32gui of Python
To automatically send an email with an attachment using the Gmail API in Python
How to get a list of files in the same directory with python
I tried to automatically send the literature of the new coronavirus to LINE with Python
[Introduction to Python] How to get the index of data with a for statement
Prepare the execution environment of Python3 with Docker
2016 The University of Tokyo Mathematics Solved with Python
Summary of how to import files in Python 3
[Note] Export the html of the site with python.
Specify the Python executable to use with virtualenv
Check the date of the flag duty with Python
Say hello to the world with Python with IntelliJ
How to deal with SessionNotCreatedException when using Selenium
Eliminate the inconveniences of QDock Widget with PySide
Character encoding when using csv module of python 2.7.3