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

semicolon does not suppress when plotting #10794

Closed
okomarov opened this issue Sep 12, 2017 · 3 comments
Closed

semicolon does not suppress when plotting #10794

okomarov opened this issue Sep 12, 2017 · 3 comments
Milestone

Comments

@okomarov
Copy link

I asked on SO and reproduce here. A notebook with two cells:

In [1]

import numpy as np
import matplotlib.pyplot as plt
from IPython.core.interactiveshell import InteractiveShell
InteractiveShell.ast_node_interactivity = "all";

In [2]

%matplotlib inline
data ={'first':np.random.rand(100), 
       'second':np.random.rand(100)}
fig, axes = plt.subplots(2)
for idx, k in enumerate(data):
    axes[idx].hist(data[k], bins=20);

does not suppress the output of the plt.hist():
screen shot 2017-09-12 at 20 43 35

Output from python -c "import IPython; print(IPython.sys_info())"

{'commit_hash': 'd86648c5d',
 'commit_source': 'installation',
 'default_encoding': 'UTF-8',
 'ipython_path': '/Users/okomarov/anaconda/lib/python3.6/site-packages/IPython',
 'ipython_version': '6.1.0',
 'os_name': 'posix',
 'platform': 'Darwin-16.7.0-x86_64-i386-64bit',
 'sys_executable': '/Users/okomarov/anaconda/bin/python3',
 'sys_platform': 'darwin',
 'sys_version': '3.6.2 |Anaconda custom (x86_64)| (default, Jul 20 2017, '
                '13:14:59) \n'
                '[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)]'}
@Carreau
Copy link
Member

Carreau commented Sep 12, 2017

You've set InteractiveShell.ast_node_interactivity = "all";, so you've set all nodes to have ast interactivity enabled.

And ; works only for the last top level expression, axes[idx].hist(data[k], bins=20); is not a top level, as it is nested in the for, the for last top level node is the for, which is a statement.

Simply add a last no-op statement, and end it with ;

%matplotlib inline
data ={'first':np.random.rand(100), 
       'second':np.random.rand(100)};
fig, axes = plt.subplots(2);
for idx, k in enumerate(data):
    axes[idx].hist(data[k], bins=20)
pass;

And you wont' have any outputs.

@Carreau Carreau added this to the no action milestone Sep 12, 2017
@okomarov
Copy link
Author

okomarov commented Sep 12, 2017

@Carreau Thanks for the clarification!

I could not find about:

And ; works only for the last top level expression

Is that documented somewhere? Would you like to copy-paste your answer in SO, so I can accept it?

@Carreau
Copy link
Member

Carreau commented Sep 12, 2017

Is that documented somewhere?

Probably not, the ast_interactivity option is so rarely used that we don't really bother with the distinction as most use case are only for the last expression.

Would you like to copy-paste your answer in so, so I can accept it?

Already did, with a couple of other details :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants