Retrieve XY data from matplotlib figure [duplicate]

This works: In [1]: import matplotlib.pyplot as plt In [2]: plt.plot([1,2,3],[4,5,6]) Out[2]: [<matplotlib.lines.Line2D at 0x30b2b10>] In [3]: ax = plt.gca() # get axis handle In [4]: line = ax.lines[0] # get the first line, there might be more In [5]: line.get_xdata() Out[5]: array([1, 2, 3]) In [6]: line.get_ydata() Out[6]: array([4, 5, 6]) In [7]: line.get_xydata() … Read more

Python – No handlers could be found for logger “OpenGL.error”

Looks like OpenGL is trying to report some error on Win2003, however you’ve not configured your system where to output logging info. You can add the following to the beginning of your program and you’ll see details of the error in stderr. import logging logging.basicConfig() Checkout documentation on logging module to get more config info, … Read more

Quick and easy: trayicon with python?

For Windows & Gnome Here ya go! wxPython is the bomb. Adapted from the source of my Feed Notifier application. import wx TRAY_TOOLTIP = ‘System Tray Demo’ TRAY_ICON = ‘icon.png’ def create_menu_item(menu, label, func): item = wx.MenuItem(menu, -1, label) menu.Bind(wx.EVT_MENU, func, id=item.GetId()) menu.AppendItem(item) return item class TaskBarIcon(wx.TaskBarIcon): def __init__(self): super(TaskBarIcon, self).__init__() self.set_icon(TRAY_ICON) self.Bind(wx.EVT_TASKBAR_LEFT_DOWN, self.on_left_down) def … Read more

Callback to python function from Tkinter Tcl crashes in windows

Each Tcl interpreter object (i.e., the context that knows how to run a Tcl procedure) can only be safely used from the OS thread that creates it. This is because Tcl doesn’t use a global interpreter lock like Python, and instead makes extensive use of thread-specific data to reduce the number of locks required internally. … Read more

How to stop a looping thread in Python?

Threaded stoppable function Instead of subclassing threading.Thread, one can modify the function to allow stopping by a flag. We need an object, accessible to running function, to which we set the flag to stop running. We can use threading.currentThread() object. import threading import time def doit(arg): t = threading.currentThread() while getattr(t, “do_run”, True): print (“working … Read more

Embedding a matplotlib figure inside a WxPython panel

This is a minimal example for a Panel with a matplotlib canvas: from numpy import arange, sin, pi import matplotlib matplotlib.use(‘WXAgg’) from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas from matplotlib.backends.backend_wx import NavigationToolbar2Wx from matplotlib.figure import Figure import wx class CanvasPanel(wx.Panel): def __init__(self, parent): wx.Panel.__init__(self, parent) self.figure = Figure() self.axes = self.figure.add_subplot(111) self.canvas = FigureCanvas(self, -1, self.figure) … Read more

Programmatically generate video or animated GIF in Python?

I’d recommend not using images2gif from visvis because it has problems with PIL/Pillow and is not actively maintained (I should know, because I am the author). Instead, please use imageio, which was developed to solve this problem and more, and is intended to stay. Quick and dirty solution: import imageio images = [] for filename … Read more