PyQtGraph – Show Text as Spots on Scatter Plot Graph
In this article, we will see how we can create a scatter plot graph in the PyQtGraph module which shows text instead of symbols as spots. 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.). A scatter plot (aka scatter chart, scatter graph) uses dots to represent values for two different numeric variables. It is a type of plot or mathematical diagram using Cartesian coordinates to display values for typically two variables for a set of data. The position of each dot on the horizontal and vertical axis indicates values for an individual data point. The main concept of showing text as spots is that we will create a text which will act as the spots.
We can create a plot window and create scatter plot graph on it with the help of commands given below.
# creating a pyqtgraph plot window plt = pg.plot() # creating a scatter plot graph of size = 10 scatter = pg.ScatterPlotItem(size=10)
1. Import pyqtgraph, pyqt5 and numpy modules
2. Create Main window class
3. Create a plot window object
4. Create a method for creating label which return the text symbol which is named tuple
5. Create random strings using numpy
6. Create random position using numpy for plotting the strings
7. Create a scatter plot item
8. Create spots using random strings and position and add them to the scatter plot
9. Add the scatter plot graph to the plot window
10. Add plot window and extra label widget to the grid layout of main window
Below is the implementation
Please Login to comment...