Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use PyQtGraph to draw the exquisite trend Chart of Shanghai Stock Index

2025-03-07 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

Today, I will talk to you about how to use PyQtGraph to draw a beautiful trend chart of the Shanghai Composite Index. Many people may not know much about it. In order to make you understand better, the editor has summarized the following contents for you. I hope you can gain something according to this article.

PyQtGraph is a Python graphics and user interface library, which provides interactive graphics drawing function, which is convenient for us to develop applications quickly. In my blog http://zmister.com, there are many articles about PyQtGraph. You are welcome to read them.

We introduce the use of PyQtGraph module to draw a complete line chart, through the tushare module to obtain the index fluctuation data of Shanghai Composite Index in the past two months as a data source. Let's explain the drawing of this broken line graph step by step.

Introduce related modules

In this example, we need to use the pyqtgraph module, the numpy module and the tushare module

Get the data source

We use the get_hist_data () method of the tushare module to obtain the historical market data of the Shanghai Composite Index from October 2017 to December 2017:

What is returned is a DataFrame data structure of Pandas, which is easy to operate.

Working with data sources

After obtaining the historical market data of the Shanghai Composite Index, we need to deal with it in order to facilitate the setting of the coordinate axis calibration text.

First, convert the date index of data into a dictionary:

Then press 5 steps to go to the data index to generate a list of index sequence numbers and index value tuples:

Draw a graph

After dealing with the data source a little bit, we are ready to draw graphics.

First instantiate a QT instance:

Then create an empty graphics window with the help of the GraphicsWindow () sub-module, and set the title of the window using the title parameter:

Set the X axis scale text of the graph through the dictionary xdict and list axis_1 created earlier, and the orientation parameter indicates the position of the axis:

Add an empty graph to the window, specify the axis and its contents through the axisItems parameter, and set the title of the graph using the title parameter:

Add a text to the drawing:

Set up the legend of the drawing:

To set the form of the graphics grid, we set the display of horizontal and vertical lines, and the transparency is only 0.5:

Draw the index of opening and closing, the pen parameter represents the color of the line, the name parameter can be used to display the legend, and symbolBrush is used to set the color of the point:

Label the axis of the drawing:

Finally, set the crosshairs:

As usual, you can call the exec_ () method of app:

Finally, run the program, and the chart is as follows:

The dynamic picture is as follows:

After reading the above, do you have any further understanding of how to use PyQtGraph to draw an exquisite trend chart of the Shanghai Composite Index? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report