2

I have some heavy plot and it's ok that it calculating couple seconds, but when i resize window/chart - its hang up for some time and that is not obviously behavior for me. How i can fix this? There is no changes in plot data, just resizing.
Demo:

import numpy as np
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk

import matplotlib
matplotlib.use('GTKCairo') 
from matplotlib.figure import Figure
from matplotlib.backends.backend_gtk3cairo import FigureCanvasGTK3Cairo as FigureCanvas

class MyApp:
    def __init__(self):
        self.Window = Gtk.Window()
        graphFig = Figure()
        graphCanvas = FigureCanvas(graphFig)
        self.Window.add(graphCanvas)

        # just example of heavy chart
        subplot = graphFig.add_subplot(111)
        for n in range(100):
            x = np.arange(0, 100, 0.01)
            y = np.sin(x) * n
            subplot.plot(x, y)

        return

    def Run(self):
        self.Window.show_all()
        Gtk.main()
        return 

App = MyApp()
App.Run()  

What options exist of fixing this issue? I wanna redraw chart only when its updated or when user pan/zoom it.

Green_Wizard
  • 795
  • 5
  • 11
  • You are drawing 100 lines of 10000 points... Depending the computer you are using it could be slow. Could you update the code with a more realistic example. Also, the use of `plt` for the axes could be misleading. People generally use `import matplotlib.pyplot as plt`. – kikocorreoso Feb 20 '16 at 19:31
  • @kikocorreoso i changed plt to subplot. – Green_Wizard Feb 20 '16 at 19:53

1 Answers1

0

To speed up plotting, consider plotting lower resolution lines. 100 lines at 1000 samples each is a lot of drawing.

Barring that, this post has a very detailed answer that could help you improve speed.

Community
  • 1
  • 1
wrkyle
  • 529
  • 1
  • 13
  • 36