Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undesired plot outputs in Notebook inline mode #2488

Closed
Panoplos opened this issue Oct 13, 2012 · 8 comments
Closed

Undesired plot outputs in Notebook inline mode #2488

Panoplos opened this issue Oct 13, 2012 · 8 comments
Milestone

Comments

@Panoplos
Copy link

Configuration:

System - OS X Lion with Python 3.2.3
IPython Version - 0.13 with cell MathJax patch
Startup -

python3 notebook --profile=sympy --pylab=inline

Example Code:

x = symbols("x")
clf()
f = ln(1 + x)
y1 = f(x)
y2 = f.series().removeO()(x)
grid(True)
plot(y1,y2,ylim=(-5.0,5.0))

Output:

Two plots are displayed, the first one is empty with the grid enabled, and the second is the y1, y2 plot without a grid.

Issue:

Calling grid(True) should not result in a outputted plot, and the plot(...) output should have grid enabled...

In fact, if I call plot(...) more than once, as in the normal usage paradigm, it should manipulate the same plot, but it outputs more than one plot at a time.

@minrk
Copy link
Member

minrk commented Oct 13, 2012

In fact, if I call plot(...) more than once, as in the normal usage paradigm, it should manipulate the same plot, but it outputs more than one plot at a time.

This is precisely the behavior I have always experienced in the notebook, so let's try to narrow down what it is about your environment that is causing this:

  • is the sympy code in your example relevant? (does the two-line cell exhibit the same behavior):

    grid(True)
    plot([1,2],[1,2])
    
  • does this happen without any config, or any sympy imports?

  • versions of matplotlib (and sympy if it affects the behavior)

  • Does identical code behave the same in a simple Python script without any IPython imports?

@jenshnielsen
Copy link
Contributor

Note that your plot function must be sympys plotting command from the sympy.plotting module. This is the only one accepting a sympy function and also the only one taking a ylim kwarg. Doing what @MinKR suggests using the mpl plot command I only see one figure.

I guess what happens is that calling grid from matplotlib creates a figure when called as the first command, after that the sympy plot command also creates a new figure.

Running the same code in the qtconsole with% pylab qt I also see to figures. In addition running the code in
pure python and saving the figure after the plot command I also get an figure without a grid. So I don't think this is
a bug in the Ipython notebook. Rather this is a bug/missing feature in the sympy plot function.

Interchanging the two commands I also get two plots in both the qtconsole and the notebook.
In the qtconsole one is blank and the other one has the desired result. In the notebook the two are just interchanged from the original result. I.e. the grid is still separated

@minrk
Copy link
Member

minrk commented Oct 13, 2012

Thanks for the clarification @jenshnielsen, closing as 'not an IPython issue'.

@minrk minrk closed this as completed Oct 13, 2012
@Panoplos
Copy link
Author

OK, so this is a namespace clobber that is not immediately apparent to the
new user. Perhaps this should be mentioned somewhere in the documentation.

On Sun, Oct 14, 2012 at 8:05 AM, Min RK notifications@github.com wrote:

Thanks for the clarification @jenshnielsenhttps://github.com/jenshnielsen,
closing as 'not an IPython issue'.


Reply to this email directly or view it on GitHubhttps://github.com//issues/2488#issuecomment-9412347.

@jenshnielsen
Copy link
Contributor

There might still be some kind of bug since the following works in the qtconsole but produces two plots in the notebook

x = symbols("x")
plt.clf()
f = ln(1 + x)
y1 = f(x)
y2 = f.series().removeO()(x)
plot(y1,y2,ylim=(-5.0,5.0))
plt.gca().grid(True)

@jenshnielsen
Copy link
Contributor

I think the namespace issue is really a sympy issue. Perhaps the sympy profile should rather do
import sympy as sp or something than from sympy import * but that breaks a lot of sympy examples.
In addition they should have used a different function name than plot. I also don't see a simple way to get the axes returned from the sympy plot function.

A related bug is #2035 where importing sympy is importing matplotlib.pyplot and thus choses the default backend for mpl
and breaks the tests that choses a specific backend. I fear that there will be quite a few ssues with the sympy plotting module
and Ipython integration as sympy 0.7.2 is released.

@jenshnielsen
Copy link
Contributor

I raised the namespace issue with the sympy devs: http://code.google.com/p/sympy/issues/detail?id=3439

@asmeurer
Copy link
Contributor

Is it expected behavior that --profile=sympy --pylab=inline runs the pylab first and the sympy second?

@minrk minrk added this to the no action milestone Mar 26, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants