Why does Jupyter Notebook need figure and axes objects in the same cell to show a figure
up vote
0
down vote
favorite
I am trying to create a simple plot using matplotlib to draw a figure in Jupyter Lab. Below is a snapshot of the code.
I create two figure objects (fig_1 and fig_2) and then add axes to them.
The axes show up in the first case when I have both the fig_1 and ax_1 objects in the same cell.
But in the second case, the image is not rendered, if the objects (fig_2 and ax_2 are in different cells).
The scope of these objects should extend beyond the cells.
Why does the image not appear in the second case?
Forgive me, if this sounds too trivial. But I am new to Jupyter Notebooks, Python and matplotlib. I am using Anaconda 4.5 with Python 3.6.5. I did try to look around but could not find an answer.
matplotlib jupyter-notebook jupyter-lab
add a comment |
up vote
0
down vote
favorite
I am trying to create a simple plot using matplotlib to draw a figure in Jupyter Lab. Below is a snapshot of the code.
I create two figure objects (fig_1 and fig_2) and then add axes to them.
The axes show up in the first case when I have both the fig_1 and ax_1 objects in the same cell.
But in the second case, the image is not rendered, if the objects (fig_2 and ax_2 are in different cells).
The scope of these objects should extend beyond the cells.
Why does the image not appear in the second case?
Forgive me, if this sounds too trivial. But I am new to Jupyter Notebooks, Python and matplotlib. I am using Anaconda 4.5 with Python 3.6.5. I did try to look around but could not find an answer.
matplotlib jupyter-notebook jupyter-lab
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am trying to create a simple plot using matplotlib to draw a figure in Jupyter Lab. Below is a snapshot of the code.
I create two figure objects (fig_1 and fig_2) and then add axes to them.
The axes show up in the first case when I have both the fig_1 and ax_1 objects in the same cell.
But in the second case, the image is not rendered, if the objects (fig_2 and ax_2 are in different cells).
The scope of these objects should extend beyond the cells.
Why does the image not appear in the second case?
Forgive me, if this sounds too trivial. But I am new to Jupyter Notebooks, Python and matplotlib. I am using Anaconda 4.5 with Python 3.6.5. I did try to look around but could not find an answer.
matplotlib jupyter-notebook jupyter-lab
I am trying to create a simple plot using matplotlib to draw a figure in Jupyter Lab. Below is a snapshot of the code.
I create two figure objects (fig_1 and fig_2) and then add axes to them.
The axes show up in the first case when I have both the fig_1 and ax_1 objects in the same cell.
But in the second case, the image is not rendered, if the objects (fig_2 and ax_2 are in different cells).
The scope of these objects should extend beyond the cells.
Why does the image not appear in the second case?
Forgive me, if this sounds too trivial. But I am new to Jupyter Notebooks, Python and matplotlib. I am using Anaconda 4.5 with Python 3.6.5. I did try to look around but could not find an answer.
matplotlib jupyter-notebook jupyter-lab
matplotlib jupyter-notebook jupyter-lab
asked yesterday
siddharth
2982413
2982413
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
I don't know enough about the notebook's internal to answer the question why, but I can tell you that if you want to display the figure in another cell, after its creation, just just have to call its instance in the cell:
Thanks. Yes, that seems to work. And makes me think that probably it renders a figure object only. In the first case, when the axes and figure are on the same cell, when the execution of the 'cell' happens, the output is the figure object and its rendered as it has axes attached to already. In the second case, first it draws a blank canvas which just appears as the text '<Figure size 432x288 with 0 Axes>'. And then one has to explicitly call figure object to render it again. Makes sense now.
– siddharth
yesterday
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
I don't know enough about the notebook's internal to answer the question why, but I can tell you that if you want to display the figure in another cell, after its creation, just just have to call its instance in the cell:
Thanks. Yes, that seems to work. And makes me think that probably it renders a figure object only. In the first case, when the axes and figure are on the same cell, when the execution of the 'cell' happens, the output is the figure object and its rendered as it has axes attached to already. In the second case, first it draws a blank canvas which just appears as the text '<Figure size 432x288 with 0 Axes>'. And then one has to explicitly call figure object to render it again. Makes sense now.
– siddharth
yesterday
add a comment |
up vote
1
down vote
accepted
I don't know enough about the notebook's internal to answer the question why, but I can tell you that if you want to display the figure in another cell, after its creation, just just have to call its instance in the cell:
Thanks. Yes, that seems to work. And makes me think that probably it renders a figure object only. In the first case, when the axes and figure are on the same cell, when the execution of the 'cell' happens, the output is the figure object and its rendered as it has axes attached to already. In the second case, first it draws a blank canvas which just appears as the text '<Figure size 432x288 with 0 Axes>'. And then one has to explicitly call figure object to render it again. Makes sense now.
– siddharth
yesterday
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
I don't know enough about the notebook's internal to answer the question why, but I can tell you that if you want to display the figure in another cell, after its creation, just just have to call its instance in the cell:
I don't know enough about the notebook's internal to answer the question why, but I can tell you that if you want to display the figure in another cell, after its creation, just just have to call its instance in the cell:
answered yesterday
Diziet Asahi
7,36031529
7,36031529
Thanks. Yes, that seems to work. And makes me think that probably it renders a figure object only. In the first case, when the axes and figure are on the same cell, when the execution of the 'cell' happens, the output is the figure object and its rendered as it has axes attached to already. In the second case, first it draws a blank canvas which just appears as the text '<Figure size 432x288 with 0 Axes>'. And then one has to explicitly call figure object to render it again. Makes sense now.
– siddharth
yesterday
add a comment |
Thanks. Yes, that seems to work. And makes me think that probably it renders a figure object only. In the first case, when the axes and figure are on the same cell, when the execution of the 'cell' happens, the output is the figure object and its rendered as it has axes attached to already. In the second case, first it draws a blank canvas which just appears as the text '<Figure size 432x288 with 0 Axes>'. And then one has to explicitly call figure object to render it again. Makes sense now.
– siddharth
yesterday
Thanks. Yes, that seems to work. And makes me think that probably it renders a figure object only. In the first case, when the axes and figure are on the same cell, when the execution of the 'cell' happens, the output is the figure object and its rendered as it has axes attached to already. In the second case, first it draws a blank canvas which just appears as the text '<Figure size 432x288 with 0 Axes>'. And then one has to explicitly call figure object to render it again. Makes sense now.
– siddharth
yesterday
Thanks. Yes, that seems to work. And makes me think that probably it renders a figure object only. In the first case, when the axes and figure are on the same cell, when the execution of the 'cell' happens, the output is the figure object and its rendered as it has axes attached to already. In the second case, first it draws a blank canvas which just appears as the text '<Figure size 432x288 with 0 Axes>'. And then one has to explicitly call figure object to render it again. Makes sense now.
– siddharth
yesterday
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53203665%2fwhy-does-jupyter-notebook-need-figure-and-axes-objects-in-the-same-cell-to-show%23new-answer', 'question_page');
}
);
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password