Skip to content

issue with display hook in base python repl #4504

Closed

Description

@tacaswell

This only applies to the base python repl, everything works in IPython repls.

In discussion on b2fbae7 discovered that sys.displayhook only gets evaluated for expressions, not statements.

This means that things like

import numpy
pass
a = b

will not trigger the auto-redrawing. This is particularly troubling because this mean

ln, = ax.plot(...)

will not trigger a re-draw, but

ax.plot(...)

will.

Due to b2fbae7, where we rely on the auto-redrawing to trigger the pyplot redrawing this means that many pyplot workflows in the normal repl are broken (as in things that used to auto-redraw no longer do).

The options I think are:

  1. figure out how to trigger a call back on statements (if this is possible, it is well hidden. There may be a reason IPython completely re-wrote the execution handling)
  2. say we only support interactive plotting with the IPython repl (which is a major regression)
  3. revert the removal of draw_if_interactive which maintains some functions as 'special'

I suspect that the answer is going to be both 2 and 3. normal python shell keeps current functionality and gains some new functionality, IPython picks up lots of new functionality, and the code base keeps this particular wart.

Activity

  1. modified the milestones: , on Jun 8, 2015
  2. added
    Release criticalFor bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions.
    API: changesChanges to the public API, typically requiring deprecation.
    on Jun 8, 2015
  3. tacaswell commented on Jun 8, 2015

    @tacaswell
    MemberAuthor

    Another option may be to hook draw_if_interactive into the callback stack on Figure objects to queue up a draw when the figure becomes stale.

  4. tacaswell commented on Jun 8, 2015

    @tacaswell
    MemberAuthor

    copied from commit thread:

    If we tie this to the state change of stale on the Figure, it will only get flipped to True once so there should only be one call to draw_if_interactive/draw_idle anyway.

    My current inclination is to change the repl registration to use the IPython hooks if they are available and the Figure-based callback otherwise.

    I will take a crack at this tomorrow morning.

  5. added a commit that references this issue on Jun 8, 2015
    494e4c7
  6. self-assigned this
    on Jun 8, 2015
  7. WeatherGod commented on Jun 25, 2015

    @WeatherGod
    Member

    Something I just noticed when playing around with the interactive mode in python REPL. If I create a figure and then call plt.ion(), the subsequent plotting call (which happens to be an expression) does not trigger a show(). Nothing shows until I do plt.show().

    >>> import matplotlib.pyplot as plt
    >>> fig, ax = plt.subplots()
    >>> ax.plot([1, 2, 3])
    [<matplotlib.lines.Line2D object at 0x7fc82dbd9c90>]
    >>> plt.ion()    # I now decide I want to see what I am doing
    >>> ax.plot([3, 2, 1])  # No figure window!
    [<matplotlib.lines.Line2D object at 0x7fc82d4a0f90>]
    >>> ax.set_xlabel('x data')  # Still no figure window!
    <matplotlib.text.Text object at 0x7fc83f0c15d0>
    >>> plt.show()  # Figure window appears
    >>> fig, ax = plt.subplots()  # New figure window appears right away and subsequent plotting calls work immediately
    
  8. OceanWolf commented on Jul 14, 2015

    @OceanWolf
    Member

    Sure, but that's expected behaviour right? The same happens with python -i not switching to interactive mode until the script has finished executing...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

API: changesChanges to the public API, typically requiring deprecation.Release criticalFor bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions.

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions