VOOZH about

URL: https://www.geeksforgeeks.org/python/plotting-data-with-timestamps-using-pyqtgraph/

⇱ Plotting Data with Timestamps using PyQtGraph - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Plotting Data with Timestamps using PyQtGraph

Last Updated : 31 Aug, 2021

In this article, we will see how we can plot data with timestamps using the PyQtGraph module in Python. PyQtGraph is a graphics and user interface library for Python that provides functionality commonly required in designing and science applications. Its primary goals are to provide fast, interactive graphics for displaying data (plots, video, etc.) and the second is to provide tools to aid in rapid application development (for example, property trees such as used in Qt Designer).

In order to install the PyQtGraph we use the command given below.

pip install pyqtgraph

A timestamp is a sequence of characters or encoded information identifying when a certain event occurred, usually giving date and time of day, sometimes accurate to a small fraction of a second. In this tutorial we will see how we can plot timestamps on x-axis and y-axis will have corresponding data with it.

In order to do so we have to do the following 

  1. Import the required libraries like pyqtgraph, pyqt5, time and numpy
  2. Create a main window class using pyqt5
  3. Create a graph window having axisitem set as DateAxisItem for timestamps
  4. Now create a data to plot in this example we will plot the sin(1/x^2) with timestamps in the last 100 years
  5. With this data plot the line graph
  6. Add the graph and other widgets to the layout of central widget of main window.


Below is the implementation.

Output : 
 

👁 Image


 

Comment
Article Tags: