GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — RuntimeError: CGContextRef is NULL with draw_artist · Issue #166 · matplotlib/matplotlib

RuntimeError: CGContextRef is NULL with draw_artist #166

New issue
Copy link
New issue
Copy link
Closed
Closed
RuntimeError: CGContextRef is NULL with draw_artist#166
Copy link
Labels
OS: Applestatus: confirmed bug

Description

@ddale
ddale
opened on Jun 20, 2011
Issue body actions

Original report at SourceForge, opened Mon Oct 4 17:04:36 2010

draw_artist on mac os x gives me an error with the following script:

import numpy as np
import matplotlib.pyplot as plt

plt.ion()
plt.figure()
subplot = plt.subplot(1,1,1)
axis = plt.imshow(np.random.random((10,10)))
plt.draw()
subplot.draw_artist(axis)
plt.show()

The traceback is:

Traceback (most recent call last):
File "matplotlib-bug.py", line 8, in
subplot.draw_artist(axis)
File "/Volumes/Data/Local/lib/python2.7/site-packages/matplotlib/axes.py", line 1946, in draw_artist
a.draw(self._cachedRenderer)
File "/Volumes/Data/Local/lib/python2.7/site-packages/matplotlib/artist.py", line 55, in draw_wrapper
draw(artist, renderer, _args, *_kwargs)
File "/Volumes/Data/Local/lib/python2.7/site-packages/matplotlib/image.py", line 338, in draw
gc = renderer.new_gc()
File "/Volumes/Data/Local/lib/python2.7/site-packages/matplotlib/backends/backend_macosx.py", line 105, in new_gc
self.gc.save()
RuntimeError: CGContextRef is NULL

matplotlib version: 1.0.0 (compiled)
python version 2.7 (binary from python.org)
macosx version: 10.6.4

SourceForge Comments

On Tue Oct 5 02:39:48 2010, nicolasrougier wrote:

I got the code from the "Animating selected plot elements" from the scipy cookbook page on animation.
The reason for this code is that I've several subplots to be drawn while I'm running the simulation. I could have used a simple call to plt.draw() but this would redraw the whole figure (is that right ?) and thus I tried to restrict the re-drawing to changing elements since the display is quite slow compared to simualtion.
The same code seems to be working on linux using the gtk backend but maybe it is not supposed to.

On Tue Oct 5 01:31:15 2010, mdehoon wrote:

I think what is happening is that graphics context functions are being called outside of the event loop. This will not work (at least not in the Mac OS X backend), since the graphics context (CGContextRef) is initialized inside the event loop. What exactly are you trying to accomplish? Can you show a full script that you would like to use for your animations? Also, is this script shown in the matplotlib documentation somewhere?

SourceForge History

  • On Tue Oct 5 01:31:15 2010, by mdehoon: assigned_to: 100

Activity

  1. dmcdougall commented on Sep 23, 2012

    @dmcdougall
    dmcdougall
    on Sep 23, 2012
    Member
    More actions

    Here's some workarounds:

    1. Instead of calling plt.draw() to draw the whole figure. One can call plt.gca() to clear the axis, and then add the updated image to the axis with a call to plt.imshow(blah).

    2. If you want to add a single artist, wouldn't a call to subplot.add_artist() suffice?

  2. pelson commented on Sep 23, 2012

    @pelson
    pelson
    on Sep 23, 2012
    Member
    More actions

    Looks like the original issue was @rougier. If you remember the scenario, would you be able to provide some more information (re @mdehoon and @dmcdougall 's questions). Thanks.

  3. rougier commented on Sep 23, 2012

    @rougier
    rougier
    on Sep 23, 2012
    Member
    More actions

    What do you mean by scenario ? If this is the original animation file, I'm not sure I still have the code.

    For the original code, I think I use the one from http://www.scipy.org/Cookbook/Matplotlib/Animations (Animating selected plot elements)

  4. astrofrog commented on Jun 24, 2013

    @astrofrog
    astrofrog
    on Jun 24, 2013
    Contributor
    More actions

    @dmcdougall @pelson - I am running into the same issue with the following code:

    import numpy as np
    
    import matplotlib
    matplotlib.use('MacOSX')
    from matplotlib import pyplot as plt
    
    fig = plt.figure()
    ax = fig.add_subplot(1,1,1)
    image = ax.imshow(np.random.random((128, 128)))
    def test_callback(event):
        ax.draw_artist(image)
    fig.canvas.mpl_connect('button_press_event', test_callback)
    plt.show()
    

    If I click anywhere in the axes (to trigger the callback) I get:

    Traceback (most recent call last):
      File "/Users/tom/Library/Python/2.7/lib/python/site-packages/matplotlib-1.4.x-py2.7-macosx-10.6-x86_64.egg/matplotlib/backend_bases.py", line 1785, in button_press_event
        self.callbacks.process(s, mouseevent)
      File "/Users/tom/Library/Python/2.7/lib/python/site-packages/matplotlib-1.4.x-py2.7-macosx-10.6-x86_64.egg/matplotlib/cbook.py", line 527, in process
        proxy(*args, **kwargs)
      File "/Users/tom/Library/Python/2.7/lib/python/site-packages/matplotlib-1.4.x-py2.7-macosx-10.6-x86_64.egg/matplotlib/cbook.py", line 405, in __call__
        return mtd(*args, **kwargs)
      File "test_draw_artist.py", line 11, in test_callback
        ax.draw_artist(image)
      File "/Users/tom/Library/Python/2.7/lib/python/site-packages/matplotlib-1.4.x-py2.7-macosx-10.6-x86_64.egg/matplotlib/axes.py", line 2098, in draw_artist
        a.draw(self._cachedRenderer)
      File "/Users/tom/Library/Python/2.7/lib/python/site-packages/matplotlib-1.4.x-py2.7-macosx-10.6-x86_64.egg/matplotlib/artist.py", line 54, in draw_wrapper
        draw(artist, renderer, *args, **kwargs)
      File "/Users/tom/Library/Python/2.7/lib/python/site-packages/matplotlib-1.4.x-py2.7-macosx-10.6-x86_64.egg/matplotlib/image.py", line 352, in draw
        gc = renderer.new_gc()
      File "/Users/tom/Library/Python/2.7/lib/python/site-packages/matplotlib-1.4.x-py2.7-macosx-10.6-x86_64.egg/matplotlib/backends/backend_macosx.py", line 97, in new_gc
        self.gc.save()
    RuntimeError: CGContextRef is NULL
    

    This is specific to the MacOSX backend.

  5. tacaswell commented on Aug 18, 2014

    @tacaswell
    tacaswell
    on Aug 18, 2014
    Member
    More actions

    This is the same problem as #2654 and #1266 closing as we have those still open.

  6. tacaswell
    closed this as completedon Aug 18, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    OS: Applestatus: confirmed bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.