NLTK Lexical Dispersion Plot does not show on Google Colab












1















The NLTK example code below runs just fine on my local system and shows the correct diagram (https://www.nltk.org/book/ch01.html#fig-inaugural):



import nltk
nltk.download('book')
from nltk.book import text4
import matplotlib
import matplotlib.pyplot
import numpy as np

text4.dispersion_plot(["citizens", "democracy", "freedom", "duties", "America"])


However, it does not show the diagram when running on Google Colab. The title and axes are displayed, size and dimensions look ok but the actual dispersion plots are invisible.



Other matplotlib.pyplot diagrams do show, also all my other notebooks run on Google Colab. I have no idea why this particular diagram does not show.



System is Ubuntu 18.04.1 LTS, browser is Firefox.










share|improve this question



























    1















    The NLTK example code below runs just fine on my local system and shows the correct diagram (https://www.nltk.org/book/ch01.html#fig-inaugural):



    import nltk
    nltk.download('book')
    from nltk.book import text4
    import matplotlib
    import matplotlib.pyplot
    import numpy as np

    text4.dispersion_plot(["citizens", "democracy", "freedom", "duties", "America"])


    However, it does not show the diagram when running on Google Colab. The title and axes are displayed, size and dimensions look ok but the actual dispersion plots are invisible.



    Other matplotlib.pyplot diagrams do show, also all my other notebooks run on Google Colab. I have no idea why this particular diagram does not show.



    System is Ubuntu 18.04.1 LTS, browser is Firefox.










    share|improve this question

























      1












      1








      1








      The NLTK example code below runs just fine on my local system and shows the correct diagram (https://www.nltk.org/book/ch01.html#fig-inaugural):



      import nltk
      nltk.download('book')
      from nltk.book import text4
      import matplotlib
      import matplotlib.pyplot
      import numpy as np

      text4.dispersion_plot(["citizens", "democracy", "freedom", "duties", "America"])


      However, it does not show the diagram when running on Google Colab. The title and axes are displayed, size and dimensions look ok but the actual dispersion plots are invisible.



      Other matplotlib.pyplot diagrams do show, also all my other notebooks run on Google Colab. I have no idea why this particular diagram does not show.



      System is Ubuntu 18.04.1 LTS, browser is Firefox.










      share|improve this question














      The NLTK example code below runs just fine on my local system and shows the correct diagram (https://www.nltk.org/book/ch01.html#fig-inaugural):



      import nltk
      nltk.download('book')
      from nltk.book import text4
      import matplotlib
      import matplotlib.pyplot
      import numpy as np

      text4.dispersion_plot(["citizens", "democracy", "freedom", "duties", "America"])


      However, it does not show the diagram when running on Google Colab. The title and axes are displayed, size and dimensions look ok but the actual dispersion plots are invisible.



      Other matplotlib.pyplot diagrams do show, also all my other notebooks run on Google Colab. I have no idea why this particular diagram does not show.



      System is Ubuntu 18.04.1 LTS, browser is Firefox.







      python nltk google-colaboratory






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jan 19 at 6:10









      nn4lnn4l

      4321617




      4321617
























          1 Answer
          1






          active

          oldest

          votes


















          1














          This bug might be related to matplotlib backend not using Tkgg or Colab's pylab library. Note that the figure is plotted using matplotlib.pylab (in NLTK's dispersion.py) and they've seemed to discourage the use of pylab. I've opened an issue here if you want to stay updated, meanwhile you can run the code from your local compiler, save the figure and use it in Colab if the output is something you need.



          You may try to display the figure in an external window instead of inline using
          %matplotlib qt, if you get a binding error try installing PyQt5 using !pip install PyQt5.



          I've tried the methods above and it didn't seem to work for me, if the issue does get resolved or if you do find a solution, do post it here, please.






          share|improve this answer























            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',
            autoActivateHeartbeat: false,
            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%2f54264548%2fnltk-lexical-dispersion-plot-does-not-show-on-google-colab%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









            1














            This bug might be related to matplotlib backend not using Tkgg or Colab's pylab library. Note that the figure is plotted using matplotlib.pylab (in NLTK's dispersion.py) and they've seemed to discourage the use of pylab. I've opened an issue here if you want to stay updated, meanwhile you can run the code from your local compiler, save the figure and use it in Colab if the output is something you need.



            You may try to display the figure in an external window instead of inline using
            %matplotlib qt, if you get a binding error try installing PyQt5 using !pip install PyQt5.



            I've tried the methods above and it didn't seem to work for me, if the issue does get resolved or if you do find a solution, do post it here, please.






            share|improve this answer




























              1














              This bug might be related to matplotlib backend not using Tkgg or Colab's pylab library. Note that the figure is plotted using matplotlib.pylab (in NLTK's dispersion.py) and they've seemed to discourage the use of pylab. I've opened an issue here if you want to stay updated, meanwhile you can run the code from your local compiler, save the figure and use it in Colab if the output is something you need.



              You may try to display the figure in an external window instead of inline using
              %matplotlib qt, if you get a binding error try installing PyQt5 using !pip install PyQt5.



              I've tried the methods above and it didn't seem to work for me, if the issue does get resolved or if you do find a solution, do post it here, please.






              share|improve this answer


























                1












                1








                1







                This bug might be related to matplotlib backend not using Tkgg or Colab's pylab library. Note that the figure is plotted using matplotlib.pylab (in NLTK's dispersion.py) and they've seemed to discourage the use of pylab. I've opened an issue here if you want to stay updated, meanwhile you can run the code from your local compiler, save the figure and use it in Colab if the output is something you need.



                You may try to display the figure in an external window instead of inline using
                %matplotlib qt, if you get a binding error try installing PyQt5 using !pip install PyQt5.



                I've tried the methods above and it didn't seem to work for me, if the issue does get resolved or if you do find a solution, do post it here, please.






                share|improve this answer













                This bug might be related to matplotlib backend not using Tkgg or Colab's pylab library. Note that the figure is plotted using matplotlib.pylab (in NLTK's dispersion.py) and they've seemed to discourage the use of pylab. I've opened an issue here if you want to stay updated, meanwhile you can run the code from your local compiler, save the figure and use it in Colab if the output is something you need.



                You may try to display the figure in an external window instead of inline using
                %matplotlib qt, if you get a binding error try installing PyQt5 using !pip install PyQt5.



                I've tried the methods above and it didn't seem to work for me, if the issue does get resolved or if you do find a solution, do post it here, please.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Jan 19 at 9:31









                specbugspecbug

                300310




                300310






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54264548%2fnltk-lexical-dispersion-plot-does-not-show-on-google-colab%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







                    Popular posts from this blog

                    Callistus III

                    Plistias Cous

                    Index Sanctorum