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
- Import the required libraries like pyqtgraph, pyqt5, time and numpy
- Create a main window class using pyqt5
- Create a graph window having axisitem set as DateAxisItem for timestamps
- Now create a data to plot in this example we will plot the sin(1/x^2) with timestamps in the last 100 years
- With this data plot the line graph
- Add the graph and other widgets to the layout of central widget of main window.
Below is the implementation.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.