Results 1 to 6 of 6

Thread: Zoom and scroll (pyqt5 -python)

  1. #1
    Join Date
    Aug 2019
    Posts
    3
    Thanks
    2
    Qt products
    Platforms
    Windows

    Default Zoom and scroll (pyqt5 -python)

    In "matplotlib" to install the viewing range of the x-axis used the function "set_xlim"
    That is, after installing "step" by means of "Slider" I used the following code:
    Qt Code:
    1. def update(evt=None):
    2. r = scroll.value() / ((1 + step) * 100)
    3. l1 = lims[0] + r * np.diff(lims)#lims - is the first and last value on the x axis(two values)
    4. l2 = l1 + np.diff(lims) * step
    5. ax.set_xlim(l1, l2)
    To copy to clipboard, switch view to plain text mode 
    So I was able to set the scale and scroll the chart.
    Is there any Qt function is similar to "set_xlim"?

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,141
    Thanks
    235
    Thanked 661 Times in 651 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: Zoom and scroll (pyqt5 -python)

    Is there any Qt function is similar to "set_xlim"?
    Your question doesn't make much sense. matplotlib is a python library for scientific graphics and has nothing to do with Qt, which is a set of C++ libraries for application development. PyQt is one of several python wrappers around parts of the Qt libraries that you can use to implement Qt GUIs in python..

    Your code looks like it is updating the value of a plot axis range based on the position of a slider. "ax" is the variable representing the axis, and "set_xlim" is the method of the axis class that sets the axis range.

    What kind of Qt class could you be looking for that would have a similar function? And why are you looking for it?
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. #3
    Join Date
    Aug 2019
    Posts
    3
    Thanks
    2
    Qt products
    Platforms
    Windows

    Default Re: Zoom and scroll (pyqt5 -python)

    Quote Originally Posted by d_stranz View Post
    Your question doesn't make much sense. matplotlib is a python library for scientific graphics and has nothing to do with Qt, which is a set of C++ libraries for application development. PyQt is one of several python wrappers around parts of the Qt libraries that you can use to implement Qt GUIs in python..

    Your code looks like it is updating the value of a plot axis range based on the position of a slider. "ax" is the variable representing the axis, and "set_xlim" is the method of the axis class that sets the axis range.

    What kind of Qt class could you be looking for that would have a similar function? And why are you looking for it?

    QtChart. Found setRange(). Question closed.
    Yes I use the scroll and zoom horizontally.

    Now I have another task. The thing is, I use a candlestick chart.
    In pyqt5, the graph is slightly faster than in matplotlib.
    But it's still slow. What I can not say about the line graph, where drawing is much faster.
    In order not to be verbose, I outlined the essence of stackoverflow https://stackoverflow.com/questions/...ible-in-python

    If not welcome reference on other resources, then request to the moderator to remove exile.
    Last edited by quant; 28th August 2019 at 23:14.

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,141
    Thanks
    235
    Thanked 661 Times in 651 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: Zoom and scroll (pyqt5 -python)

    QtChart. Found setRange(). Question closed.
    Then you weren't asking about a specific matplotlib function at all. You were asking about a complete Qt-based replacement for a plot that you can produce in matplotlib.

    But it's still slow.
    The problem (from your stackoverflow post) is that you are updating the axis for every single move of the scrollbar. QtChart will redraw itself every time the axis range is updated. If you have 40,000 candles, every candle will be redrawn on every step. Of course it will be slow.

    One solution is to not update the axis for every step, but only update the plot when the slider finally stops moving. Or update it every 10 steps and again when it stops moving.

    To suspend updates while the slider is moving, implement a QTimer with a timeout of 200 ms or something like that. Each time the slider moves, you record the current position in a member variable for your class and restart the timer for another 200 ms. When the user stops moving the slider, the timer will timeout. In the timeout slot, you finally update the axis with the final slider value. By repeatedly restarting the time, you ensure that nothing gets drawn until 200 ms after the slider finally stops moving.

    If you want to periodically update the plot even while the slider is still moving, you can do the same thing with the QTimer, but also add a member variable that counts the number of steps. Whenever steps == 10 (or whatever), update the axis and set steps = 0, otherwise just set steps = steps + 1 and do nothing. The QTimer will ensure that when the slider stops moving, the plot will be updated with the final value no matter how many steps there were.

    The timer + step counting method will give something that looks almost like a real time update, but will give you much better performance. You can set the numbers of steps or timeout so that the scrolling looks smooth because the redraw can keep up with the slider.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  5. The following user says thank you to d_stranz for this useful post:

    quant (29th August 2019)

  6. #5
    Join Date
    Aug 2019
    Posts
    3
    Thanks
    2
    Qt products
    Platforms
    Windows

    Default Re: Zoom and scroll (pyqt5 -python)

    Quote Originally Posted by d_stranz View Post

    The problem (from your stackoverflow post) is that you are updating the axis for every single move of the scrollbar. QtChart will redraw itself every time the axis range is updated. If you have 40,000 candles, every candle will be redrawn on every step. Of course it will be slow.
    Thanks, I'll try!
    In Python, there are only about 7000 candles, it is in the graph on C# 40,000 candles.
    C# uses the "chart control" library, which is not considered fast.

  7. #6
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,141
    Thanks
    235
    Thanked 661 Times in 651 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: Zoom and scroll (pyqt5 -python)

    Thanks, I'll try!
    Another thing you can try: If the line plot is fast, then think about drawing only a line plot during zooming or scrolling. That is, when scrolling starts, replace the candle plot series with a line series and update that. When scrolling stops, replace the line series with the candle series again. You can use the QTimer trick to know when scrolling has stopped. You will give the impression of real time scrolling, but you will have only a small fraction of the things to draw.

    I don't think users will care if the candles disappear during scrolling. Many graphics software apps reduce the level of detail during interactive procedures to get better performance. As soon as scrolling stops, the full plot will reappear.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  8. The following user says thank you to d_stranz for this useful post:

    quant (29th August 2019)

Similar Threads

  1. PyQt5 with python: LineEdit set text
    By rwahdan in forum Qt Programming
    Replies: 0
    Last Post: 15th June 2019, 11:42
  2. Replies: 1
    Last Post: 3rd July 2018, 23:44
  3. Python / PyQt5 MDI Window focus problem
    By apereira in forum Newbie
    Replies: 5
    Last Post: 21st September 2015, 23:29
  4. Replies: 0
    Last Post: 26th July 2015, 04:45
  5. Replies: 2
    Last Post: 13th January 2009, 04:32

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.