Tag: pyqtgraph. I'm writing a GUI for a camera and I'd like to have a widget with the live stream from the camera. This indeed works and I would be happy with it if it wasn't for the fact that I also need the intensity histogram on the side. This only works for a few frames I can see the images changing and the histogram moving accordingly and then the whole GUI freezes. Has anyone seen this behaviour? Regarding the freezing: If I run your code generating random data rather than pulling from a camera, it runs just fine.
I suspect the problem lies elsewhere. Are you perhaps using multiple threads incorrectly? You may need to post a more complete example, and do some testing to determine where the program is hanging up.
I think this might be a Qt bug. GraphicsLayout l. GraphicsView view. QGraphicsWidget : simple graphics Your problem stems from the fact that you need to return control to the Qt event loop for it to redraw the picture. Since you remain in the UpdateWhileRec callback while waiting for the next image to be acquired, Qt never gets a chance to draw the image.
It only Personally, I don't put any effort into chasing exit crashes anymore--just use pg. Just a simple error: you need super CamParamTree, self. Here is what I have sort of put together by pulling several threads online: Ruby On Rails seems to be more popular than python at this moment.Qt C++ 02 Mouse Scrolling with Custom Graphics View
If you go python, Flask and Django are good templates. Take a look at this gist. You could modify tickStrings to change format string according to scale.
To restate the question: you want to have two views that can have different ranges and scales, but when you zoom with the mouse in one view, the other view will zoom by the same amount. I figured it out-- using the lower-level ImageItem class displayed the image in a way that stretched to fit the window size: self. QApplication  self. GraphicsLayoutWidget self. ImageItem self. QTimer self. Clipping is supported, but probably not the best option. This would also allow you to add multiple arcs to a single item rather than adding many items, which should improve performance.Think you could help me "pop" the data so the segment in the window scrolls past a fixed time segment instead of continuously appending?
I'm able to get past a couple of other obstacles but this one I don't have a clue on. It works fantastically other than this, same with several examples from pyqtgraph BUT I can't seem to get how to control the x axis to show a fixed segment of time Hi, I am new to Arduino. Any leads as to how i can achieve this? Hit ctrl-c if you want to stop logging. You can use tee to see and log the stream at the same time. If you want to do it in python, you just have to take the above code and write the variable line to a file.
Skip to content. Instantly share code, notes, and snippets. Code Revisions 1 Stars 6 Forks 2. Embed What would you like to do?
Embed Embed this gist in your website. Share Copy sharable link for this gist. Learn more about clone URLs. Download ZIP. Code to read data from the serial port and plot it.
Qt import QtGuiQtCore import numpy as np import pyqtgraph as pg from pyqtgraph. QTimer timer. This comment has been minimized. Sign in to view. Copy link Quote reply. Thanks for sharing. Just a question: why do you import 'time' from 'pyqtgraph. Sign up for free to join this conversation on GitHub. Already have an account?
Sign in to comment. You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Qt import QtGuiQtCore. QApplication .Tag: pyqtgraph. I'm trying to create an scrolling plot window with PyQtGraph. The plot itself has multiple axes.
I used this as the basis of the multiple axes. I used this one as the base to do the scrolling bit. My problem is that for my data, the scrolling plot seems to acquire an y-offset, increasing as time goes on. I also tried using the same data to display in an accumulating plot though I really would rather to do a scrolling view and it didn't acquire any y-offset.
This is what it looks at the end of my test sample - missing the effect of y-offset gradually increasing. Of course, I would like for the y-offset not to appear, the top plot should be identical to the last 50 samples of the bottom plot.
Simple error: both curves in the top plot are shifted in the y-direction because of these lines:. Personally, I don't put any effort into chasing exit crashes anymore--just use pg.
To restate the question: you want to have two views that can have different ranges and scales, but when you zoom with the mouse in one view, the other view will zoom by the same amount. Simple error: both curves in the top plot are shifted in the y-direction because of these lines: curve1. AxisItem is not designed to do what you want. You will need to either call AxisItem. To make a plot scroll, you have three options: Scroll the raw data and re-plot see numpy. I think this might be a Qt bug.
GraphicsLayout l. GraphicsView view. QGraphicsWidget : simple graphics Yep, same problem here if I try to use the built-in python on the mac. This is hard. In theory you could use a VNC-like approach that sends an image of the window to the client browser and sends user events back to the server. This will probably have poor interactivity depending on the networking and would require a lot of server power, depending on If you want text out of the global namespace, make it an attribute of the MyGLView class.
Example: import pyqtgraph. I finally found it. I somehow never realized, that you HAVE to use numpy arrays. Qt makes it simple to map between coordinate systems with its QGraphicsItem. PyQtGraph further extends these with even more pg.
Point 3, 1 PyQt4. QPointF When you connect a signal to a lambda function, the contents of the lambda function are evaluated when the signal is emitted, not when the signal is connected. Instead of hiding the axis, try axis.
This might only be available in the development branch You a few options, probably any of which would work: Join the programs into one, with a worker thread that monitors for data and sends this back to the main thread for plotting. One strategy is to connect to GraphicsScene.This section describes mouse interaction with these widgets. For machines where dragging with the right or middle buttons is difficult usually Macanother mouse interaction mode exists.
In this mode, dragging with the left mouse button draws a box over a region of the scene. After the button is released, the scene is scaled and panned to fit the box. This mode can be accessed in the context menu or by calling:.
Right-clicking on most scenes will show a context menu with various options for changing the behavior of the scene. Some of the options available in this menu are:. The exact set of items available in the menu depends on the contents of the scene and the object clicked on. If there are no movable objects under the mouse cursor, then dragging with the left button will pan the scene instead.
Right button drag: Scales the scene. Right button click: Clicking the right button in most cases will show a context menu with a variety of options depending on the object s under the mouse cursor.
Source code for pyqtgraph.widgets.MultiPlotWidget
Middle button or wheel drag: Dragging the mouse with the wheel pressed down will always pan the scene this is useful in instances where panning with the left button is prevented by other objects in the scene.
Wheel spin: Zooms the scene in and out. This mode can be accessed in the context menu or by calling: pyqtgraph.GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together. Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community. Already on GitHub? Sign in to your account.
I have built a scrolling chart that loads data from a pandas dataframe that is populated from another process. It creates PlotDataItems with data points each.
PyQtGraph: Live video stream freezes using ImageView
Then applies np. This is then added to an array of PlotDataItems. These are shifted using setPos. I have found that when I add a 'symbol' argument to the plot method see belowthe previous PlotDataItems do not get shifted left during the shift process. However, the current or latest PlotDataItem shifts to the left, correctly.
PNG' - I've outlined this behaviour using the vertical lime green lines at the left of the screenshot where the top symbol-based plotdataitems get out of sync with the 'white line' plotdataitem. However, when I take out the symbol argument, the second line scrolls to the left perfectly as you probably know - this a modification from one of your samples.
PNG' screenshot for how this works correctly. Thanks for publishing and continuing to support this very useful charting package. Much appreciated. Skip to content. Dismiss Join GitHub today GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together. Sign up. New issue. Jump to bottom. Copy link Quote reply. Hello - My environment: pyqtgraph 0. Best, Mark M.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment. Linked pull requests. You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window.Please share with friends and colleagues!
One of the major strengths of Python is in exploratory data science and visualization, using tools such as Pandas, numpy, sklearn for data analysis and matplotlib plotting.
Buiding GUI applications with PyQt gives you access to all these Python tools directly from within your app, allowing you to build complex data-driven apps and interactive dashboards. While it is possible to embed matplotlib plots in PyQt the experience does not feel entirely native. For simple and highly interactive plots you may want to consider using PyQtGraph instead.
PyQtGraph is built on top of PyQ5 native QGraphicsScene giving better drawing performance, particularly for live data, as well as providing interactivity and the ability to easily customize plots with Qt graphics widgets.
In this tutorial we'll walk through the first steps of creating a plot widget with PyQtGraph and then demonstrate plot customization using line colours, line type, axis labels, background colour and plotting multiple lines.
You can do this as normal using pip. This widget provides a contained canvas on which plots of any type can be added and configured. Under the hood, this plot widget uses Qt native QGraphicsScene meaning it fast and efficient yet simple to integrate with the rest of your app. You can create a PlotWidget as for any other widget.
In the following examples we'll create the PyQtGraph widget in code. See Embedding custom widgets from Qt Designer. In all our examples below we import PyQtGraph using import pyqtgraph as pg. You an import and use it as import pyqtgraph if you prefer. In the next section we'll look at what options we have available to us in PyQtGraph to improve the appearance and usability of our plots. This gives us access to all the standard Qt line and shape styling options for use in plots.
Below we'll go through the most common styling features you'll need to create and customize your own plots. Beginning with the app skeleton above, we can change the background colour by calling.
The code below will set the background to white, by passing in the string 'w'. There are a number of simple colours available using single letters, based on the standard colours used in matplotlib. They're pretty unsurprising, except that 'k' is used for black. In addition to these single letter codes, you can also set more complex colours using hex notation eg.
This can be useful if you're using specific QColor objects elsewhere in your application, or to set your plot background to the default GUI background colour.
This gives you the same full control over line drawing as you would have in any other QGraphicsScene drawing.
To use a pen to plot a line, you simply create a new QPen instance and pass it into the plot method. Below we create a QPen object, passing in a 3-tuple of int values specifying an RGB value of full red. We could also define this by passing 'r', or a QColor object.
Then we pass this into plot with the pen parameter. By changing the QPen object we can change the appearance of the line, including both line width in pixels and style dashed, dotted, etc. For example, the following example creates a 15px width dashed line in red.
The standard Qt line styles can all be used, including Qt. SolidLineQt. DashLineQt.Bases: GraphicsWidget. Add a QGraphicsItem to this view. The view will include this item when determining how to set its range automatically unless ignoreBounds is True. Set the range of the view box to make all children visible. Note that this is not the same as enableAutoRange, which causes the view to automatically auto-range whenever its contents are changed. Return the transform that maps from child item in the childGroup coordinates to local coordinates.
This maps from inside the viewbox to outside. Return the bounding range of all children. Enable or disable auto-range for axiswhich may be ViewBox. XAxis, ViewBox. YAxis, or ViewBox. XYAxes for both if axis is omitted, both axes will be changed.
The argument enable may optionally be a float 0. Return the current state of the ViewBox. Linked views are always converted to view names in the returned state. By default, the positive x-axis points rightward on the screen. Use invertX True to reverse the x-axis. By default, the positive y-axis points upward on the screen.
Plotting with PyQtGraph
Use invertY True to reverse the y-axis. This routine should capture key presses in the current view box. Link X or Y axes of two views and unlink any previously connected axes. XAxis or ViewBox. If view is None, the axis is left unlinked. Temporarily display the bounding rect of an item and lines connecting to the center of the view. This is useful for determining the location of items that may be out of the range of the ViewBox.