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.



enter image description here



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.










share|improve this question


























    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.



    enter image description here



    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.










    share|improve this question
























      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.



      enter image description here



      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.










      share|improve this question













      I am trying to create a simple plot using matplotlib to draw a figure in Jupyter Lab. Below is a snapshot of the code.



      enter image description here



      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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked yesterday









      siddharth

      2982413




      2982413
























          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:



          enter image description here






          share|improve this answer





















          • 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













          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














           

          draft saved


          draft discarded


















          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
































          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:



          enter image description here






          share|improve this answer





















          • 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

















          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:



          enter image description here






          share|improve this answer





















          • 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















          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:



          enter image description here






          share|improve this answer












          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:



          enter image description here







          share|improve this answer












          share|improve this answer



          share|improve this answer










          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




















          • 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




















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          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




















































































          Popular posts from this blog

          Schultheiß

          Verwaltungsgliederung Dänemarks

          Liste der Kulturdenkmale in Wilsdruff