question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ChartMPL redraws too readily

See original GitHub issue

Describe the bug, what’s wrong, and what you expected.

in ChartMPL, a callback to self._redraw is connected to the canvas on draw_event https://github.com/pyvista/pyvista/blob/fb108591f941f7452c05905da3fb9c13a54f92dc/pyvista/plotting/charts.py#L4184 which grabs the canvas buffer and makes a new vtkImageData object.

The problem is that the draw_event happens rapidly, even just by moving the mouse across the plot window without any updates to the plot dimensions or underlying plot image or data. This causes performance issues.

Ideally, the _redraw method shouldn’t be called so often, or some caching could be used to speed this up. Matplotlib is a very great library to rely upon for plotting but I wouldn’t expect the canvas to be redrawn so often.

Steps to reproduce the bug.

 Insert code here 

System Information

--------------------------------------------------------------------------------
  Date: Sat Jul 02 20:15:06 2022 PDT
                OS : Darwin
            CPU(s) : 8
           Machine : x86_64
      Architecture : 64bit
               RAM : 16.0 GiB
       Environment : IPython
       File system : apfs
        GPU Vendor : ATI Technologies Inc.
      GPU Renderer : AMD Radeon Pro 560 OpenGL Engine
       GPU Version : 4.1 ATI-4.6.21
  Python 3.10.4 | packaged by conda-forge | (main, Mar 24 2022, 17:43:32)
  [Clang 12.0.1 ]
           pyvista : 0.34.0
               vtk : 9.1.0
             numpy : 1.21.6
           imageio : 2.16.1
           appdirs : 1.4.4
            scooby : 0.5.12
        matplotlib : 3.5.2
         pyvistaqt : 0.9.0
           IPython : 8.3.0
          colorcet : 3.0.0
        ipyvtklink : 0.2.2
             scipy : 1.8.0
              tqdm : 4.63.0
            meshio : 5.3.4
--------------------------------------------------------------------------------

Screenshots

No response

Code of Conduct

  • I agree to follow this project’s Code of Conduct

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
AndrewAnnexcommented, Jul 4, 2022

@dcbr try clicking and dragging across the plotter window. I am developing a little app for my research which uses a multiplot so the following updated code example should illustrate the issue:

import pyvista as pv

p = pv.Plotter(shape=(1,2))
p.subplot(0, 0)
p.add_mesh(pv.Cube())

p.subplot(0,1)
chart = pv.ChartMPL()
p.add_chart(chart)

chart._canvas.mpl_connect('draw_event', lambda *args: print("redraw"))

p.show()

I agree the call to _redraw is needed when the canvas is updated, but currently the redraw method is being called without any significant or real state change. Maybe some timeout based cache could be used or if there is a more specific event to use (like if the canvas data changes or if the window is resized… etc).

0reactions
dcbrcommented, Jul 5, 2022

Exactly, I verified the dynamic updates still work by running the chart_overlays example.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Source code for pyvista.plotting.charts
"Very large"] >>> chart.show() Revert back to automatic tick placement. > ... interface for vtkChart, vtkChartBox, vtkChartPie and ChartMPL instances.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found