Graphics plotting provides distorted and unusable plots with Python 2.7 after upgrading to Ubuntu 18.04












0















My Python 2.7 code that I've been running in Ubuntu 16.04 does some simple graphics plotting routines that provide distorted and unusable plots now that I've upgraded to Ubuntu 18.04. I get no error messages or warnings. I'm NOT running python3 in the new Ubuntu and the version I'm invoking is python version 2.7.15rcq. Any suggestions?



The Python libraries that are imported are:

  scipy

  pylab

  math



and a couple that probably aren't relevant to this plotting problem.










share|improve this question




















  • 2





    Please edit your question and include some details, such as what package are you using for the plotting e.g. matplotlib?

    – Carl H
    Jul 25 '18 at 12:55






  • 1





    I don't see anything especially wrong with the formatting of this question and I'm voting to leave it open. Wondering a bit though about the default python and whether you've adjusted things package-wise since the upgrade. Showing your code might be a good idea - you can drop it in a pastebin if it's long.

    – Zanna
    Jul 25 '18 at 17:27











  • Python 3 is the default Python version in Ubuntu 18.04. Python 3 is automatically installed if it doesn't already exist on your system when it is upgraded to Ubuntu 18.04.

    – karel
    Jan 11 at 6:54


















0















My Python 2.7 code that I've been running in Ubuntu 16.04 does some simple graphics plotting routines that provide distorted and unusable plots now that I've upgraded to Ubuntu 18.04. I get no error messages or warnings. I'm NOT running python3 in the new Ubuntu and the version I'm invoking is python version 2.7.15rcq. Any suggestions?



The Python libraries that are imported are:

  scipy

  pylab

  math



and a couple that probably aren't relevant to this plotting problem.










share|improve this question




















  • 2





    Please edit your question and include some details, such as what package are you using for the plotting e.g. matplotlib?

    – Carl H
    Jul 25 '18 at 12:55






  • 1





    I don't see anything especially wrong with the formatting of this question and I'm voting to leave it open. Wondering a bit though about the default python and whether you've adjusted things package-wise since the upgrade. Showing your code might be a good idea - you can drop it in a pastebin if it's long.

    – Zanna
    Jul 25 '18 at 17:27











  • Python 3 is the default Python version in Ubuntu 18.04. Python 3 is automatically installed if it doesn't already exist on your system when it is upgraded to Ubuntu 18.04.

    – karel
    Jan 11 at 6:54
















0












0








0








My Python 2.7 code that I've been running in Ubuntu 16.04 does some simple graphics plotting routines that provide distorted and unusable plots now that I've upgraded to Ubuntu 18.04. I get no error messages or warnings. I'm NOT running python3 in the new Ubuntu and the version I'm invoking is python version 2.7.15rcq. Any suggestions?



The Python libraries that are imported are:

  scipy

  pylab

  math



and a couple that probably aren't relevant to this plotting problem.










share|improve this question
















My Python 2.7 code that I've been running in Ubuntu 16.04 does some simple graphics plotting routines that provide distorted and unusable plots now that I've upgraded to Ubuntu 18.04. I get no error messages or warnings. I'm NOT running python3 in the new Ubuntu and the version I'm invoking is python version 2.7.15rcq. Any suggestions?



The Python libraries that are imported are:

  scipy

  pylab

  math



and a couple that probably aren't relevant to this plotting problem.







18.04 python-2.7 plot






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 11 at 6:49









karel

58.6k13128147




58.6k13128147










asked Jul 25 '18 at 12:42









Steve DSteve D

61




61








  • 2





    Please edit your question and include some details, such as what package are you using for the plotting e.g. matplotlib?

    – Carl H
    Jul 25 '18 at 12:55






  • 1





    I don't see anything especially wrong with the formatting of this question and I'm voting to leave it open. Wondering a bit though about the default python and whether you've adjusted things package-wise since the upgrade. Showing your code might be a good idea - you can drop it in a pastebin if it's long.

    – Zanna
    Jul 25 '18 at 17:27











  • Python 3 is the default Python version in Ubuntu 18.04. Python 3 is automatically installed if it doesn't already exist on your system when it is upgraded to Ubuntu 18.04.

    – karel
    Jan 11 at 6:54
















  • 2





    Please edit your question and include some details, such as what package are you using for the plotting e.g. matplotlib?

    – Carl H
    Jul 25 '18 at 12:55






  • 1





    I don't see anything especially wrong with the formatting of this question and I'm voting to leave it open. Wondering a bit though about the default python and whether you've adjusted things package-wise since the upgrade. Showing your code might be a good idea - you can drop it in a pastebin if it's long.

    – Zanna
    Jul 25 '18 at 17:27











  • Python 3 is the default Python version in Ubuntu 18.04. Python 3 is automatically installed if it doesn't already exist on your system when it is upgraded to Ubuntu 18.04.

    – karel
    Jan 11 at 6:54










2




2





Please edit your question and include some details, such as what package are you using for the plotting e.g. matplotlib?

– Carl H
Jul 25 '18 at 12:55





Please edit your question and include some details, such as what package are you using for the plotting e.g. matplotlib?

– Carl H
Jul 25 '18 at 12:55




1




1





I don't see anything especially wrong with the formatting of this question and I'm voting to leave it open. Wondering a bit though about the default python and whether you've adjusted things package-wise since the upgrade. Showing your code might be a good idea - you can drop it in a pastebin if it's long.

– Zanna
Jul 25 '18 at 17:27





I don't see anything especially wrong with the formatting of this question and I'm voting to leave it open. Wondering a bit though about the default python and whether you've adjusted things package-wise since the upgrade. Showing your code might be a good idea - you can drop it in a pastebin if it's long.

– Zanna
Jul 25 '18 at 17:27













Python 3 is the default Python version in Ubuntu 18.04. Python 3 is automatically installed if it doesn't already exist on your system when it is upgraded to Ubuntu 18.04.

– karel
Jan 11 at 6:54







Python 3 is the default Python version in Ubuntu 18.04. Python 3 is automatically installed if it doesn't already exist on your system when it is upgraded to Ubuntu 18.04.

– karel
Jan 11 at 6:54












1 Answer
1






active

oldest

votes


















2














Python IDE for scientists (spyder) can do inline plotting. To try out this feature open the terminal and type:



sudo apt install python2.7 ipython python-matplotlib spyder  


After the ipython prompt in the IPython console copy/paste the below code and press the Enter key to run it.



import matplotlib.pyplot as plt   
x, y = [-1, 12], [1, 4]
plt.plot(x, y, marker = 'o')


enter image description here



If that works try the following Python code which uses scipy, pylab and math modules.



import pylab as plb
import matplotlib.pyplot as plt
from scipy.optimize import curve_fit
from scipy import asarray as ar,exp
import math

x=ar([37,69,157,238,274,319,391,495,533,626,1366,1855,2821,3615,4130,4374,6453,6863,7021,
7951,8646,9656,10464,11400])
y=ar([1.77,1.67,1.65,1.17,1.34,1.46,0.75,1,0.8,1.02,0.65,0.69,0.44,0.44,0.55,0.43,0.75,0.27,0.26,
0.44,0.04,0.44,0.26,0.04])

n = 24 # the number of data
mean = sum(x*y)/n # note this correction
sigma = math.sqrt(sum(y*(x-mean)**2)/n) # note this correction

def gaus(x,a,sigma):
return a*exp(-(x)**2/(2*sigma**2))

p0 = [1.2, 4000]
popt,pcov = curve_fit(gaus,x,y,p0=p0)

plt.plot(x,y,'b+:',label='data')
plt.plot(x,gaus(x,*popt),'ro:',label='fit')
plt.legend()
plt.title('Fig. 3 - Fit for Time Constant')
plt.xlabel('Time (s)')
plt.ylabel('Voltage (V)')
plt.show()

def gaus(x,a,sigma):
return a*exp(-(x)**2/(2*sigma**2))

p0 = [1.2, 4000]
popt,pcov = curve_fit(gaus,x,y,p0=p0)


The output is shown in the below screenshot.



enter image description here
(Click image to enlarge)



The output shows this warning:



Warning: pylab (numpy and matplotlib) and symbolic math (sympy) are both 
enabled at the same time. Some pylab functions are going to be overrided by
the sympy module (e.g. plot).


... but the plot is output correctly despite this warning message.



In order to eliminate the warning message remove the import pylab as plb at line 1 from the code. Clicking the triangular icon to the left of line 1 shows the following syntax checking message.



'pylab as plb' imported but unused  


The syntax checking message is correct. The code outputs exactly the same plot when line 1 is removed. Sometimes it helps to use an IDE when debugging lengthy blocks of code because an IDE has features like syntax checking.






share|improve this answer

























    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "89"
    };
    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%2faskubuntu.com%2fquestions%2f1059365%2fgraphics-plotting-provides-distorted-and-unusable-plots-with-python-2-7-after-up%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









    2














    Python IDE for scientists (spyder) can do inline plotting. To try out this feature open the terminal and type:



    sudo apt install python2.7 ipython python-matplotlib spyder  


    After the ipython prompt in the IPython console copy/paste the below code and press the Enter key to run it.



    import matplotlib.pyplot as plt   
    x, y = [-1, 12], [1, 4]
    plt.plot(x, y, marker = 'o')


    enter image description here



    If that works try the following Python code which uses scipy, pylab and math modules.



    import pylab as plb
    import matplotlib.pyplot as plt
    from scipy.optimize import curve_fit
    from scipy import asarray as ar,exp
    import math

    x=ar([37,69,157,238,274,319,391,495,533,626,1366,1855,2821,3615,4130,4374,6453,6863,7021,
    7951,8646,9656,10464,11400])
    y=ar([1.77,1.67,1.65,1.17,1.34,1.46,0.75,1,0.8,1.02,0.65,0.69,0.44,0.44,0.55,0.43,0.75,0.27,0.26,
    0.44,0.04,0.44,0.26,0.04])

    n = 24 # the number of data
    mean = sum(x*y)/n # note this correction
    sigma = math.sqrt(sum(y*(x-mean)**2)/n) # note this correction

    def gaus(x,a,sigma):
    return a*exp(-(x)**2/(2*sigma**2))

    p0 = [1.2, 4000]
    popt,pcov = curve_fit(gaus,x,y,p0=p0)

    plt.plot(x,y,'b+:',label='data')
    plt.plot(x,gaus(x,*popt),'ro:',label='fit')
    plt.legend()
    plt.title('Fig. 3 - Fit for Time Constant')
    plt.xlabel('Time (s)')
    plt.ylabel('Voltage (V)')
    plt.show()

    def gaus(x,a,sigma):
    return a*exp(-(x)**2/(2*sigma**2))

    p0 = [1.2, 4000]
    popt,pcov = curve_fit(gaus,x,y,p0=p0)


    The output is shown in the below screenshot.



    enter image description here
    (Click image to enlarge)



    The output shows this warning:



    Warning: pylab (numpy and matplotlib) and symbolic math (sympy) are both 
    enabled at the same time. Some pylab functions are going to be overrided by
    the sympy module (e.g. plot).


    ... but the plot is output correctly despite this warning message.



    In order to eliminate the warning message remove the import pylab as plb at line 1 from the code. Clicking the triangular icon to the left of line 1 shows the following syntax checking message.



    'pylab as plb' imported but unused  


    The syntax checking message is correct. The code outputs exactly the same plot when line 1 is removed. Sometimes it helps to use an IDE when debugging lengthy blocks of code because an IDE has features like syntax checking.






    share|improve this answer






























      2














      Python IDE for scientists (spyder) can do inline plotting. To try out this feature open the terminal and type:



      sudo apt install python2.7 ipython python-matplotlib spyder  


      After the ipython prompt in the IPython console copy/paste the below code and press the Enter key to run it.



      import matplotlib.pyplot as plt   
      x, y = [-1, 12], [1, 4]
      plt.plot(x, y, marker = 'o')


      enter image description here



      If that works try the following Python code which uses scipy, pylab and math modules.



      import pylab as plb
      import matplotlib.pyplot as plt
      from scipy.optimize import curve_fit
      from scipy import asarray as ar,exp
      import math

      x=ar([37,69,157,238,274,319,391,495,533,626,1366,1855,2821,3615,4130,4374,6453,6863,7021,
      7951,8646,9656,10464,11400])
      y=ar([1.77,1.67,1.65,1.17,1.34,1.46,0.75,1,0.8,1.02,0.65,0.69,0.44,0.44,0.55,0.43,0.75,0.27,0.26,
      0.44,0.04,0.44,0.26,0.04])

      n = 24 # the number of data
      mean = sum(x*y)/n # note this correction
      sigma = math.sqrt(sum(y*(x-mean)**2)/n) # note this correction

      def gaus(x,a,sigma):
      return a*exp(-(x)**2/(2*sigma**2))

      p0 = [1.2, 4000]
      popt,pcov = curve_fit(gaus,x,y,p0=p0)

      plt.plot(x,y,'b+:',label='data')
      plt.plot(x,gaus(x,*popt),'ro:',label='fit')
      plt.legend()
      plt.title('Fig. 3 - Fit for Time Constant')
      plt.xlabel('Time (s)')
      plt.ylabel('Voltage (V)')
      plt.show()

      def gaus(x,a,sigma):
      return a*exp(-(x)**2/(2*sigma**2))

      p0 = [1.2, 4000]
      popt,pcov = curve_fit(gaus,x,y,p0=p0)


      The output is shown in the below screenshot.



      enter image description here
      (Click image to enlarge)



      The output shows this warning:



      Warning: pylab (numpy and matplotlib) and symbolic math (sympy) are both 
      enabled at the same time. Some pylab functions are going to be overrided by
      the sympy module (e.g. plot).


      ... but the plot is output correctly despite this warning message.



      In order to eliminate the warning message remove the import pylab as plb at line 1 from the code. Clicking the triangular icon to the left of line 1 shows the following syntax checking message.



      'pylab as plb' imported but unused  


      The syntax checking message is correct. The code outputs exactly the same plot when line 1 is removed. Sometimes it helps to use an IDE when debugging lengthy blocks of code because an IDE has features like syntax checking.






      share|improve this answer




























        2












        2








        2







        Python IDE for scientists (spyder) can do inline plotting. To try out this feature open the terminal and type:



        sudo apt install python2.7 ipython python-matplotlib spyder  


        After the ipython prompt in the IPython console copy/paste the below code and press the Enter key to run it.



        import matplotlib.pyplot as plt   
        x, y = [-1, 12], [1, 4]
        plt.plot(x, y, marker = 'o')


        enter image description here



        If that works try the following Python code which uses scipy, pylab and math modules.



        import pylab as plb
        import matplotlib.pyplot as plt
        from scipy.optimize import curve_fit
        from scipy import asarray as ar,exp
        import math

        x=ar([37,69,157,238,274,319,391,495,533,626,1366,1855,2821,3615,4130,4374,6453,6863,7021,
        7951,8646,9656,10464,11400])
        y=ar([1.77,1.67,1.65,1.17,1.34,1.46,0.75,1,0.8,1.02,0.65,0.69,0.44,0.44,0.55,0.43,0.75,0.27,0.26,
        0.44,0.04,0.44,0.26,0.04])

        n = 24 # the number of data
        mean = sum(x*y)/n # note this correction
        sigma = math.sqrt(sum(y*(x-mean)**2)/n) # note this correction

        def gaus(x,a,sigma):
        return a*exp(-(x)**2/(2*sigma**2))

        p0 = [1.2, 4000]
        popt,pcov = curve_fit(gaus,x,y,p0=p0)

        plt.plot(x,y,'b+:',label='data')
        plt.plot(x,gaus(x,*popt),'ro:',label='fit')
        plt.legend()
        plt.title('Fig. 3 - Fit for Time Constant')
        plt.xlabel('Time (s)')
        plt.ylabel('Voltage (V)')
        plt.show()

        def gaus(x,a,sigma):
        return a*exp(-(x)**2/(2*sigma**2))

        p0 = [1.2, 4000]
        popt,pcov = curve_fit(gaus,x,y,p0=p0)


        The output is shown in the below screenshot.



        enter image description here
        (Click image to enlarge)



        The output shows this warning:



        Warning: pylab (numpy and matplotlib) and symbolic math (sympy) are both 
        enabled at the same time. Some pylab functions are going to be overrided by
        the sympy module (e.g. plot).


        ... but the plot is output correctly despite this warning message.



        In order to eliminate the warning message remove the import pylab as plb at line 1 from the code. Clicking the triangular icon to the left of line 1 shows the following syntax checking message.



        'pylab as plb' imported but unused  


        The syntax checking message is correct. The code outputs exactly the same plot when line 1 is removed. Sometimes it helps to use an IDE when debugging lengthy blocks of code because an IDE has features like syntax checking.






        share|improve this answer















        Python IDE for scientists (spyder) can do inline plotting. To try out this feature open the terminal and type:



        sudo apt install python2.7 ipython python-matplotlib spyder  


        After the ipython prompt in the IPython console copy/paste the below code and press the Enter key to run it.



        import matplotlib.pyplot as plt   
        x, y = [-1, 12], [1, 4]
        plt.plot(x, y, marker = 'o')


        enter image description here



        If that works try the following Python code which uses scipy, pylab and math modules.



        import pylab as plb
        import matplotlib.pyplot as plt
        from scipy.optimize import curve_fit
        from scipy import asarray as ar,exp
        import math

        x=ar([37,69,157,238,274,319,391,495,533,626,1366,1855,2821,3615,4130,4374,6453,6863,7021,
        7951,8646,9656,10464,11400])
        y=ar([1.77,1.67,1.65,1.17,1.34,1.46,0.75,1,0.8,1.02,0.65,0.69,0.44,0.44,0.55,0.43,0.75,0.27,0.26,
        0.44,0.04,0.44,0.26,0.04])

        n = 24 # the number of data
        mean = sum(x*y)/n # note this correction
        sigma = math.sqrt(sum(y*(x-mean)**2)/n) # note this correction

        def gaus(x,a,sigma):
        return a*exp(-(x)**2/(2*sigma**2))

        p0 = [1.2, 4000]
        popt,pcov = curve_fit(gaus,x,y,p0=p0)

        plt.plot(x,y,'b+:',label='data')
        plt.plot(x,gaus(x,*popt),'ro:',label='fit')
        plt.legend()
        plt.title('Fig. 3 - Fit for Time Constant')
        plt.xlabel('Time (s)')
        plt.ylabel('Voltage (V)')
        plt.show()

        def gaus(x,a,sigma):
        return a*exp(-(x)**2/(2*sigma**2))

        p0 = [1.2, 4000]
        popt,pcov = curve_fit(gaus,x,y,p0=p0)


        The output is shown in the below screenshot.



        enter image description here
        (Click image to enlarge)



        The output shows this warning:



        Warning: pylab (numpy and matplotlib) and symbolic math (sympy) are both 
        enabled at the same time. Some pylab functions are going to be overrided by
        the sympy module (e.g. plot).


        ... but the plot is output correctly despite this warning message.



        In order to eliminate the warning message remove the import pylab as plb at line 1 from the code. Clicking the triangular icon to the left of line 1 shows the following syntax checking message.



        'pylab as plb' imported but unused  


        The syntax checking message is correct. The code outputs exactly the same plot when line 1 is removed. Sometimes it helps to use an IDE when debugging lengthy blocks of code because an IDE has features like syntax checking.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Jan 10 at 17:30

























        answered Jul 25 '18 at 15:25









        karelkarel

        58.6k13128147




        58.6k13128147






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Ask Ubuntu!


            • 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%2faskubuntu.com%2fquestions%2f1059365%2fgraphics-plotting-provides-distorted-and-unusable-plots-with-python-2-7-after-up%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

            flock() on closed filehandle LOCK_FILE at /usr/bin/apt-mirror

            Mangá

            Eduardo VII do Reino Unido