pyplot.contourf() returns error when specified levels argument









up vote
1
down vote

favorite












EDIT: The issue is most likely about the version. The levels argument takes an integer argument in version 3.0.0, while this issue has occurred while using version 2.2.2.



I'm trying to make a contour plot in Python using the matplotlib.pyplot.contourf() function, and it works perfectly like this:



plt.contourf(x, y, z)


but when I try to specify an integer for the levels argument, like this:



plt.contourf(x, y, z, levels=100)


it always returns the error: TypeError: len() of unsized object



In the documentation, it says that the argument levels can be either int or array_like so I don't know why it would even call the len() function



Any ideas why this happens and any suggestion on how to fix it?










share|improve this question



























    up vote
    1
    down vote

    favorite












    EDIT: The issue is most likely about the version. The levels argument takes an integer argument in version 3.0.0, while this issue has occurred while using version 2.2.2.



    I'm trying to make a contour plot in Python using the matplotlib.pyplot.contourf() function, and it works perfectly like this:



    plt.contourf(x, y, z)


    but when I try to specify an integer for the levels argument, like this:



    plt.contourf(x, y, z, levels=100)


    it always returns the error: TypeError: len() of unsized object



    In the documentation, it says that the argument levels can be either int or array_like so I don't know why it would even call the len() function



    Any ideas why this happens and any suggestion on how to fix it?










    share|improve this question

























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      EDIT: The issue is most likely about the version. The levels argument takes an integer argument in version 3.0.0, while this issue has occurred while using version 2.2.2.



      I'm trying to make a contour plot in Python using the matplotlib.pyplot.contourf() function, and it works perfectly like this:



      plt.contourf(x, y, z)


      but when I try to specify an integer for the levels argument, like this:



      plt.contourf(x, y, z, levels=100)


      it always returns the error: TypeError: len() of unsized object



      In the documentation, it says that the argument levels can be either int or array_like so I don't know why it would even call the len() function



      Any ideas why this happens and any suggestion on how to fix it?










      share|improve this question















      EDIT: The issue is most likely about the version. The levels argument takes an integer argument in version 3.0.0, while this issue has occurred while using version 2.2.2.



      I'm trying to make a contour plot in Python using the matplotlib.pyplot.contourf() function, and it works perfectly like this:



      plt.contourf(x, y, z)


      but when I try to specify an integer for the levels argument, like this:



      plt.contourf(x, y, z, levels=100)


      it always returns the error: TypeError: len() of unsized object



      In the documentation, it says that the argument levels can be either int or array_like so I don't know why it would even call the len() function



      Any ideas why this happens and any suggestion on how to fix it?







      python matplotlib typeerror contourf






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 16 at 18:52

























      asked Nov 10 at 20:52









      vejtics

      133




      133






















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          Sorry, this happens to you. The documentation changed in version 2.2.3 without this feature being fully implemented. So depending on the version of matplotlib the levels argument is interpreted differently.



          matplotlib < 3.0.0



          levels is interpreted as a list of levels where to draw contours. An integer is interpreted as a single level. For a contourf (a filled contour) plot you need at least two levels. Use the previously known way to specfify the number of levels as the second or fourth unnamed argument



          plt.contourf(z, 100)
          plt.contourf(x, y, z, 100)


          matplotlib >= 3.0.0



          levels can take either a list or an integer. When an integer, it signifies the (approximate [*]) number of levels. The relevant PR is this.



          plt.contourf(z, levels=100)
          plt.contourf(x, y, z, levels=100)





          share|improve this answer






















          • This shouldn't be the case, but perhaps I have a version older than 3.0.0.
            – vejtics
            Nov 16 at 0:33










          • I checked. That's indeed the issue (I was running version 2.2.2).
            – vejtics
            Nov 16 at 18:49










          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%2f53243303%2fpyplot-contourf-returns-error-when-specified-levels-argument%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          1
          down vote



          accepted










          Sorry, this happens to you. The documentation changed in version 2.2.3 without this feature being fully implemented. So depending on the version of matplotlib the levels argument is interpreted differently.



          matplotlib < 3.0.0



          levels is interpreted as a list of levels where to draw contours. An integer is interpreted as a single level. For a contourf (a filled contour) plot you need at least two levels. Use the previously known way to specfify the number of levels as the second or fourth unnamed argument



          plt.contourf(z, 100)
          plt.contourf(x, y, z, 100)


          matplotlib >= 3.0.0



          levels can take either a list or an integer. When an integer, it signifies the (approximate [*]) number of levels. The relevant PR is this.



          plt.contourf(z, levels=100)
          plt.contourf(x, y, z, levels=100)





          share|improve this answer






















          • This shouldn't be the case, but perhaps I have a version older than 3.0.0.
            – vejtics
            Nov 16 at 0:33










          • I checked. That's indeed the issue (I was running version 2.2.2).
            – vejtics
            Nov 16 at 18:49














          up vote
          1
          down vote



          accepted










          Sorry, this happens to you. The documentation changed in version 2.2.3 without this feature being fully implemented. So depending on the version of matplotlib the levels argument is interpreted differently.



          matplotlib < 3.0.0



          levels is interpreted as a list of levels where to draw contours. An integer is interpreted as a single level. For a contourf (a filled contour) plot you need at least two levels. Use the previously known way to specfify the number of levels as the second or fourth unnamed argument



          plt.contourf(z, 100)
          plt.contourf(x, y, z, 100)


          matplotlib >= 3.0.0



          levels can take either a list or an integer. When an integer, it signifies the (approximate [*]) number of levels. The relevant PR is this.



          plt.contourf(z, levels=100)
          plt.contourf(x, y, z, levels=100)





          share|improve this answer






















          • This shouldn't be the case, but perhaps I have a version older than 3.0.0.
            – vejtics
            Nov 16 at 0:33










          • I checked. That's indeed the issue (I was running version 2.2.2).
            – vejtics
            Nov 16 at 18:49












          up vote
          1
          down vote



          accepted







          up vote
          1
          down vote



          accepted






          Sorry, this happens to you. The documentation changed in version 2.2.3 without this feature being fully implemented. So depending on the version of matplotlib the levels argument is interpreted differently.



          matplotlib < 3.0.0



          levels is interpreted as a list of levels where to draw contours. An integer is interpreted as a single level. For a contourf (a filled contour) plot you need at least two levels. Use the previously known way to specfify the number of levels as the second or fourth unnamed argument



          plt.contourf(z, 100)
          plt.contourf(x, y, z, 100)


          matplotlib >= 3.0.0



          levels can take either a list or an integer. When an integer, it signifies the (approximate [*]) number of levels. The relevant PR is this.



          plt.contourf(z, levels=100)
          plt.contourf(x, y, z, levels=100)





          share|improve this answer














          Sorry, this happens to you. The documentation changed in version 2.2.3 without this feature being fully implemented. So depending on the version of matplotlib the levels argument is interpreted differently.



          matplotlib < 3.0.0



          levels is interpreted as a list of levels where to draw contours. An integer is interpreted as a single level. For a contourf (a filled contour) plot you need at least two levels. Use the previously known way to specfify the number of levels as the second or fourth unnamed argument



          plt.contourf(z, 100)
          plt.contourf(x, y, z, 100)


          matplotlib >= 3.0.0



          levels can take either a list or an integer. When an integer, it signifies the (approximate [*]) number of levels. The relevant PR is this.



          plt.contourf(z, levels=100)
          plt.contourf(x, y, z, levels=100)






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 10 at 21:32

























          answered Nov 10 at 21:12









          ImportanceOfBeingErnest

          119k10117190




          119k10117190











          • This shouldn't be the case, but perhaps I have a version older than 3.0.0.
            – vejtics
            Nov 16 at 0:33










          • I checked. That's indeed the issue (I was running version 2.2.2).
            – vejtics
            Nov 16 at 18:49
















          • This shouldn't be the case, but perhaps I have a version older than 3.0.0.
            – vejtics
            Nov 16 at 0:33










          • I checked. That's indeed the issue (I was running version 2.2.2).
            – vejtics
            Nov 16 at 18:49















          This shouldn't be the case, but perhaps I have a version older than 3.0.0.
          – vejtics
          Nov 16 at 0:33




          This shouldn't be the case, but perhaps I have a version older than 3.0.0.
          – vejtics
          Nov 16 at 0:33












          I checked. That's indeed the issue (I was running version 2.2.2).
          – vejtics
          Nov 16 at 18:49




          I checked. That's indeed the issue (I was running version 2.2.2).
          – vejtics
          Nov 16 at 18:49

















           

          draft saved


          draft discarded















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53243303%2fpyplot-contourf-returns-error-when-specified-levels-argument%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          這個網誌中的熱門文章

          How to read a connectionString WITH PROVIDER in .NET Core?

          In R, how to develop a multiplot heatmap.2 figure showing key labels successfully

          Museum of Modern and Contemporary Art of Trento and Rovereto