Plot simple functions like sine of x with IPython












1















My teacher plotted some functions with Jupyter Notebook or IPython. I have installed Jupyter Notebook and have the home screen, but how can I plot a function?



I have already tried: plot sin(x) but I get this message:



  File "<ipython-input-4-7979a129f00f>", line 1
plot sin(x)
^
SyntaxError: invalid syntax


Screenshot










share|improve this question




















  • 1





    what is plot sin(x) suppose to mean? Cuz I doubt a "space" in there is valid syntax. A valid python command line could be y = plot.sin(x) where plot is the name of an import module numpy(?) as plot.

    – Rinzwind
    Nov 3 '16 at 14:32













  • Was your teacher using plain Python via Jupyter or maybe SageMath? If it works for you I can provide an answer with SageMath. Or Pylab.

    – Andrea Lazzarotto
    Nov 3 '16 at 14:33
















1















My teacher plotted some functions with Jupyter Notebook or IPython. I have installed Jupyter Notebook and have the home screen, but how can I plot a function?



I have already tried: plot sin(x) but I get this message:



  File "<ipython-input-4-7979a129f00f>", line 1
plot sin(x)
^
SyntaxError: invalid syntax


Screenshot










share|improve this question




















  • 1





    what is plot sin(x) suppose to mean? Cuz I doubt a "space" in there is valid syntax. A valid python command line could be y = plot.sin(x) where plot is the name of an import module numpy(?) as plot.

    – Rinzwind
    Nov 3 '16 at 14:32













  • Was your teacher using plain Python via Jupyter or maybe SageMath? If it works for you I can provide an answer with SageMath. Or Pylab.

    – Andrea Lazzarotto
    Nov 3 '16 at 14:33














1












1








1


1






My teacher plotted some functions with Jupyter Notebook or IPython. I have installed Jupyter Notebook and have the home screen, but how can I plot a function?



I have already tried: plot sin(x) but I get this message:



  File "<ipython-input-4-7979a129f00f>", line 1
plot sin(x)
^
SyntaxError: invalid syntax


Screenshot










share|improve this question
















My teacher plotted some functions with Jupyter Notebook or IPython. I have installed Jupyter Notebook and have the home screen, but how can I plot a function?



I have already tried: plot sin(x) but I get this message:



  File "<ipython-input-4-7979a129f00f>", line 1
plot sin(x)
^
SyntaxError: invalid syntax


Screenshot







python ipython jupyter matplotlib plot






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 9 '18 at 8:38









karel

57.8k12128146




57.8k12128146










asked Nov 3 '16 at 14:14









Stap DenisovStap Denisov

912




912








  • 1





    what is plot sin(x) suppose to mean? Cuz I doubt a "space" in there is valid syntax. A valid python command line could be y = plot.sin(x) where plot is the name of an import module numpy(?) as plot.

    – Rinzwind
    Nov 3 '16 at 14:32













  • Was your teacher using plain Python via Jupyter or maybe SageMath? If it works for you I can provide an answer with SageMath. Or Pylab.

    – Andrea Lazzarotto
    Nov 3 '16 at 14:33














  • 1





    what is plot sin(x) suppose to mean? Cuz I doubt a "space" in there is valid syntax. A valid python command line could be y = plot.sin(x) where plot is the name of an import module numpy(?) as plot.

    – Rinzwind
    Nov 3 '16 at 14:32













  • Was your teacher using plain Python via Jupyter or maybe SageMath? If it works for you I can provide an answer with SageMath. Or Pylab.

    – Andrea Lazzarotto
    Nov 3 '16 at 14:33








1




1





what is plot sin(x) suppose to mean? Cuz I doubt a "space" in there is valid syntax. A valid python command line could be y = plot.sin(x) where plot is the name of an import module numpy(?) as plot.

– Rinzwind
Nov 3 '16 at 14:32







what is plot sin(x) suppose to mean? Cuz I doubt a "space" in there is valid syntax. A valid python command line could be y = plot.sin(x) where plot is the name of an import module numpy(?) as plot.

– Rinzwind
Nov 3 '16 at 14:32















Was your teacher using plain Python via Jupyter or maybe SageMath? If it works for you I can provide an answer with SageMath. Or Pylab.

– Andrea Lazzarotto
Nov 3 '16 at 14:33





Was your teacher using plain Python via Jupyter or maybe SageMath? If it works for you I can provide an answer with SageMath. Or Pylab.

– Andrea Lazzarotto
Nov 3 '16 at 14:33










1 Answer
1






active

oldest

votes


















6














From the terminal type:



sudo apt-get install ipython-notebook python-numpy python-matplotlib  


The latest version of IPython Notebook is now known as the Jupyter Notebook. You can optionally install Jupyter Notebook instead of IPython Notebook. In Ubuntu 14.04/16.04/16.10 follow the instructions in this answer to install Jupyter Notebook by upgrading IPython Notebook to Jupyter Notebook. In Ubuntu 17.04 and 17.10 you can install Jupyter Notebook from the default Ubuntu repositories with the command sudo apt install jupyter-notebook jupyter-core python-ipykernel. In Ubuntu 18.04 and later you can install Jupyter Notebook from the default Ubuntu repositories with the command sudo apt install python3-notebook jupyter-core python-ipykernel. python-ipykernel is necessary for running Python 2.x programs in Jupyter Notebook, which otherwise supports only Python 3.x. If Jupyter Notebook is installed, the command to start Jupyter is jupyter notebook and the first line of code to enable plotting in the current Notebook is %matplotlib inline.



Follow these steps to generate the sine wave plot in the example from matplotlib.org.





  1. Open the ipython-notebook web browser interface. From the terminal run:



    ipython notebook --pylab  


    The --pylab option was removed when they transitioned from IPython to Jupyter notebook. Instead use jupyter notebook to start Jupyter.



  2. Make a new notebook. From the IPython Notebook interface click the New Notebook button. A new notebook tab will open in your default web browser. From the new notebook tab select File -> Rename, rename your new notebook to any descriptive name like sine_wave and click the OK button.



  3. Copy the example Python code for plotting a sine wave listed below and paste it into the sine_wave notebook to the right of where it says In [1]: using the keyboard combination Ctrl+V. Paste the whole code block together, not one line at a time.



    import matplotlib.pyplot as plt  
    import numpy as np

    t = np.arange(0.0, 2.0, 0.01)
    s = np.sin(2*np.pi*t)
    plt.plot(t, s)

    plt.xlabel('time (s)')
    plt.ylabel('voltage (mV)')
    plt.title('voltage (mV) vs. time (sec)')
    plt.grid(True)
    plt.savefig("plot-voltage-vs.-time.png")
    plt.show()


    plt.savefig("plot-voltage-vs.-time.png") saves an image of your plot without all the extra window chrome in your Home directory.



  4. Click the black triangular-shaped Run button ( ) on the menu bar to run the code block.



  5. Your output plot will appear in a small popup window that looks like the popup window in the below screenshot.



    IMG:




  6. Repeat steps 3. and 4. to run a new code block (In [2]:). Try pasting the following simple Python code after In [2]: and running it.



    import matplotlib.pyplot as plt  
    import numpy as np

    x = np.arange(0.0, 2.0, 0.01)
    y = np.sin(2*np.pi*x)
    plt.plot(x, y)
    plt.show()



The error message ImportError: No module named 'matplotlib' was caused by using Python 3 with Jupyter that was installed for Python 2.x. It is possible to use Python 3 in Jupyter Notebook for Python 2 by adding the kernel for Python 2. If you're running Jupyter on Python 3, you can set up a Python 2 kernel like this:



python2 -m pip install ipykernel
python2 -m ipykernel install --user





share|improve this answer


























  • Hey. First thank you a lot for your answer. I am trying to do that, but when i type the code and run it, i get an Error . It says at the End: "ImportError: no module named "matplotlib" What can i do?

    – Stap Denisov
    Nov 22 '16 at 13:22













  • 1. Check if the python-matplotlib package is installed. 2. If you are using Jupyter, the first line of code to enable plotting in the current Notebook needs to be %matplotlib inline

    – karel
    Nov 22 '16 at 15:19











  • 1. i did that in the console: sudo apt-get install python-matplotlib. I guess that is the matplotib package. 2. Before entering the code in jupyter i typed "%matplotlib inline" in In[1 ]. After running this line i get the same error``???

    – Stap Denisov
    Nov 22 '16 at 15:31













  • I installed Jupyter Notebook and ran the code from my answer and it worked fine in my Jupyter Notebook, so I know that the code is OK. I installed Jupyter Notebook by following these instructions: askubuntu.com/questions/847263/…

    – karel
    Nov 22 '16 at 16:00













  • i think that the code is ok. And i installed jupyter the same way. but why do i get this error, when i already installed matplotlib...?? (ImportError: No module named "matplotlib")

    – Stap Denisov
    Nov 22 '16 at 17:21











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%2f845111%2fplot-simple-functions-like-sine-of-x-with-ipython%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









6














From the terminal type:



sudo apt-get install ipython-notebook python-numpy python-matplotlib  


The latest version of IPython Notebook is now known as the Jupyter Notebook. You can optionally install Jupyter Notebook instead of IPython Notebook. In Ubuntu 14.04/16.04/16.10 follow the instructions in this answer to install Jupyter Notebook by upgrading IPython Notebook to Jupyter Notebook. In Ubuntu 17.04 and 17.10 you can install Jupyter Notebook from the default Ubuntu repositories with the command sudo apt install jupyter-notebook jupyter-core python-ipykernel. In Ubuntu 18.04 and later you can install Jupyter Notebook from the default Ubuntu repositories with the command sudo apt install python3-notebook jupyter-core python-ipykernel. python-ipykernel is necessary for running Python 2.x programs in Jupyter Notebook, which otherwise supports only Python 3.x. If Jupyter Notebook is installed, the command to start Jupyter is jupyter notebook and the first line of code to enable plotting in the current Notebook is %matplotlib inline.



Follow these steps to generate the sine wave plot in the example from matplotlib.org.





  1. Open the ipython-notebook web browser interface. From the terminal run:



    ipython notebook --pylab  


    The --pylab option was removed when they transitioned from IPython to Jupyter notebook. Instead use jupyter notebook to start Jupyter.



  2. Make a new notebook. From the IPython Notebook interface click the New Notebook button. A new notebook tab will open in your default web browser. From the new notebook tab select File -> Rename, rename your new notebook to any descriptive name like sine_wave and click the OK button.



  3. Copy the example Python code for plotting a sine wave listed below and paste it into the sine_wave notebook to the right of where it says In [1]: using the keyboard combination Ctrl+V. Paste the whole code block together, not one line at a time.



    import matplotlib.pyplot as plt  
    import numpy as np

    t = np.arange(0.0, 2.0, 0.01)
    s = np.sin(2*np.pi*t)
    plt.plot(t, s)

    plt.xlabel('time (s)')
    plt.ylabel('voltage (mV)')
    plt.title('voltage (mV) vs. time (sec)')
    plt.grid(True)
    plt.savefig("plot-voltage-vs.-time.png")
    plt.show()


    plt.savefig("plot-voltage-vs.-time.png") saves an image of your plot without all the extra window chrome in your Home directory.



  4. Click the black triangular-shaped Run button ( ) on the menu bar to run the code block.



  5. Your output plot will appear in a small popup window that looks like the popup window in the below screenshot.



    IMG:




  6. Repeat steps 3. and 4. to run a new code block (In [2]:). Try pasting the following simple Python code after In [2]: and running it.



    import matplotlib.pyplot as plt  
    import numpy as np

    x = np.arange(0.0, 2.0, 0.01)
    y = np.sin(2*np.pi*x)
    plt.plot(x, y)
    plt.show()



The error message ImportError: No module named 'matplotlib' was caused by using Python 3 with Jupyter that was installed for Python 2.x. It is possible to use Python 3 in Jupyter Notebook for Python 2 by adding the kernel for Python 2. If you're running Jupyter on Python 3, you can set up a Python 2 kernel like this:



python2 -m pip install ipykernel
python2 -m ipykernel install --user





share|improve this answer


























  • Hey. First thank you a lot for your answer. I am trying to do that, but when i type the code and run it, i get an Error . It says at the End: "ImportError: no module named "matplotlib" What can i do?

    – Stap Denisov
    Nov 22 '16 at 13:22













  • 1. Check if the python-matplotlib package is installed. 2. If you are using Jupyter, the first line of code to enable plotting in the current Notebook needs to be %matplotlib inline

    – karel
    Nov 22 '16 at 15:19











  • 1. i did that in the console: sudo apt-get install python-matplotlib. I guess that is the matplotib package. 2. Before entering the code in jupyter i typed "%matplotlib inline" in In[1 ]. After running this line i get the same error``???

    – Stap Denisov
    Nov 22 '16 at 15:31













  • I installed Jupyter Notebook and ran the code from my answer and it worked fine in my Jupyter Notebook, so I know that the code is OK. I installed Jupyter Notebook by following these instructions: askubuntu.com/questions/847263/…

    – karel
    Nov 22 '16 at 16:00













  • i think that the code is ok. And i installed jupyter the same way. but why do i get this error, when i already installed matplotlib...?? (ImportError: No module named "matplotlib")

    – Stap Denisov
    Nov 22 '16 at 17:21
















6














From the terminal type:



sudo apt-get install ipython-notebook python-numpy python-matplotlib  


The latest version of IPython Notebook is now known as the Jupyter Notebook. You can optionally install Jupyter Notebook instead of IPython Notebook. In Ubuntu 14.04/16.04/16.10 follow the instructions in this answer to install Jupyter Notebook by upgrading IPython Notebook to Jupyter Notebook. In Ubuntu 17.04 and 17.10 you can install Jupyter Notebook from the default Ubuntu repositories with the command sudo apt install jupyter-notebook jupyter-core python-ipykernel. In Ubuntu 18.04 and later you can install Jupyter Notebook from the default Ubuntu repositories with the command sudo apt install python3-notebook jupyter-core python-ipykernel. python-ipykernel is necessary for running Python 2.x programs in Jupyter Notebook, which otherwise supports only Python 3.x. If Jupyter Notebook is installed, the command to start Jupyter is jupyter notebook and the first line of code to enable plotting in the current Notebook is %matplotlib inline.



Follow these steps to generate the sine wave plot in the example from matplotlib.org.





  1. Open the ipython-notebook web browser interface. From the terminal run:



    ipython notebook --pylab  


    The --pylab option was removed when they transitioned from IPython to Jupyter notebook. Instead use jupyter notebook to start Jupyter.



  2. Make a new notebook. From the IPython Notebook interface click the New Notebook button. A new notebook tab will open in your default web browser. From the new notebook tab select File -> Rename, rename your new notebook to any descriptive name like sine_wave and click the OK button.



  3. Copy the example Python code for plotting a sine wave listed below and paste it into the sine_wave notebook to the right of where it says In [1]: using the keyboard combination Ctrl+V. Paste the whole code block together, not one line at a time.



    import matplotlib.pyplot as plt  
    import numpy as np

    t = np.arange(0.0, 2.0, 0.01)
    s = np.sin(2*np.pi*t)
    plt.plot(t, s)

    plt.xlabel('time (s)')
    plt.ylabel('voltage (mV)')
    plt.title('voltage (mV) vs. time (sec)')
    plt.grid(True)
    plt.savefig("plot-voltage-vs.-time.png")
    plt.show()


    plt.savefig("plot-voltage-vs.-time.png") saves an image of your plot without all the extra window chrome in your Home directory.



  4. Click the black triangular-shaped Run button ( ) on the menu bar to run the code block.



  5. Your output plot will appear in a small popup window that looks like the popup window in the below screenshot.



    IMG:




  6. Repeat steps 3. and 4. to run a new code block (In [2]:). Try pasting the following simple Python code after In [2]: and running it.



    import matplotlib.pyplot as plt  
    import numpy as np

    x = np.arange(0.0, 2.0, 0.01)
    y = np.sin(2*np.pi*x)
    plt.plot(x, y)
    plt.show()



The error message ImportError: No module named 'matplotlib' was caused by using Python 3 with Jupyter that was installed for Python 2.x. It is possible to use Python 3 in Jupyter Notebook for Python 2 by adding the kernel for Python 2. If you're running Jupyter on Python 3, you can set up a Python 2 kernel like this:



python2 -m pip install ipykernel
python2 -m ipykernel install --user





share|improve this answer


























  • Hey. First thank you a lot for your answer. I am trying to do that, but when i type the code and run it, i get an Error . It says at the End: "ImportError: no module named "matplotlib" What can i do?

    – Stap Denisov
    Nov 22 '16 at 13:22













  • 1. Check if the python-matplotlib package is installed. 2. If you are using Jupyter, the first line of code to enable plotting in the current Notebook needs to be %matplotlib inline

    – karel
    Nov 22 '16 at 15:19











  • 1. i did that in the console: sudo apt-get install python-matplotlib. I guess that is the matplotib package. 2. Before entering the code in jupyter i typed "%matplotlib inline" in In[1 ]. After running this line i get the same error``???

    – Stap Denisov
    Nov 22 '16 at 15:31













  • I installed Jupyter Notebook and ran the code from my answer and it worked fine in my Jupyter Notebook, so I know that the code is OK. I installed Jupyter Notebook by following these instructions: askubuntu.com/questions/847263/…

    – karel
    Nov 22 '16 at 16:00













  • i think that the code is ok. And i installed jupyter the same way. but why do i get this error, when i already installed matplotlib...?? (ImportError: No module named "matplotlib")

    – Stap Denisov
    Nov 22 '16 at 17:21














6












6








6







From the terminal type:



sudo apt-get install ipython-notebook python-numpy python-matplotlib  


The latest version of IPython Notebook is now known as the Jupyter Notebook. You can optionally install Jupyter Notebook instead of IPython Notebook. In Ubuntu 14.04/16.04/16.10 follow the instructions in this answer to install Jupyter Notebook by upgrading IPython Notebook to Jupyter Notebook. In Ubuntu 17.04 and 17.10 you can install Jupyter Notebook from the default Ubuntu repositories with the command sudo apt install jupyter-notebook jupyter-core python-ipykernel. In Ubuntu 18.04 and later you can install Jupyter Notebook from the default Ubuntu repositories with the command sudo apt install python3-notebook jupyter-core python-ipykernel. python-ipykernel is necessary for running Python 2.x programs in Jupyter Notebook, which otherwise supports only Python 3.x. If Jupyter Notebook is installed, the command to start Jupyter is jupyter notebook and the first line of code to enable plotting in the current Notebook is %matplotlib inline.



Follow these steps to generate the sine wave plot in the example from matplotlib.org.





  1. Open the ipython-notebook web browser interface. From the terminal run:



    ipython notebook --pylab  


    The --pylab option was removed when they transitioned from IPython to Jupyter notebook. Instead use jupyter notebook to start Jupyter.



  2. Make a new notebook. From the IPython Notebook interface click the New Notebook button. A new notebook tab will open in your default web browser. From the new notebook tab select File -> Rename, rename your new notebook to any descriptive name like sine_wave and click the OK button.



  3. Copy the example Python code for plotting a sine wave listed below and paste it into the sine_wave notebook to the right of where it says In [1]: using the keyboard combination Ctrl+V. Paste the whole code block together, not one line at a time.



    import matplotlib.pyplot as plt  
    import numpy as np

    t = np.arange(0.0, 2.0, 0.01)
    s = np.sin(2*np.pi*t)
    plt.plot(t, s)

    plt.xlabel('time (s)')
    plt.ylabel('voltage (mV)')
    plt.title('voltage (mV) vs. time (sec)')
    plt.grid(True)
    plt.savefig("plot-voltage-vs.-time.png")
    plt.show()


    plt.savefig("plot-voltage-vs.-time.png") saves an image of your plot without all the extra window chrome in your Home directory.



  4. Click the black triangular-shaped Run button ( ) on the menu bar to run the code block.



  5. Your output plot will appear in a small popup window that looks like the popup window in the below screenshot.



    IMG:




  6. Repeat steps 3. and 4. to run a new code block (In [2]:). Try pasting the following simple Python code after In [2]: and running it.



    import matplotlib.pyplot as plt  
    import numpy as np

    x = np.arange(0.0, 2.0, 0.01)
    y = np.sin(2*np.pi*x)
    plt.plot(x, y)
    plt.show()



The error message ImportError: No module named 'matplotlib' was caused by using Python 3 with Jupyter that was installed for Python 2.x. It is possible to use Python 3 in Jupyter Notebook for Python 2 by adding the kernel for Python 2. If you're running Jupyter on Python 3, you can set up a Python 2 kernel like this:



python2 -m pip install ipykernel
python2 -m ipykernel install --user





share|improve this answer















From the terminal type:



sudo apt-get install ipython-notebook python-numpy python-matplotlib  


The latest version of IPython Notebook is now known as the Jupyter Notebook. You can optionally install Jupyter Notebook instead of IPython Notebook. In Ubuntu 14.04/16.04/16.10 follow the instructions in this answer to install Jupyter Notebook by upgrading IPython Notebook to Jupyter Notebook. In Ubuntu 17.04 and 17.10 you can install Jupyter Notebook from the default Ubuntu repositories with the command sudo apt install jupyter-notebook jupyter-core python-ipykernel. In Ubuntu 18.04 and later you can install Jupyter Notebook from the default Ubuntu repositories with the command sudo apt install python3-notebook jupyter-core python-ipykernel. python-ipykernel is necessary for running Python 2.x programs in Jupyter Notebook, which otherwise supports only Python 3.x. If Jupyter Notebook is installed, the command to start Jupyter is jupyter notebook and the first line of code to enable plotting in the current Notebook is %matplotlib inline.



Follow these steps to generate the sine wave plot in the example from matplotlib.org.





  1. Open the ipython-notebook web browser interface. From the terminal run:



    ipython notebook --pylab  


    The --pylab option was removed when they transitioned from IPython to Jupyter notebook. Instead use jupyter notebook to start Jupyter.



  2. Make a new notebook. From the IPython Notebook interface click the New Notebook button. A new notebook tab will open in your default web browser. From the new notebook tab select File -> Rename, rename your new notebook to any descriptive name like sine_wave and click the OK button.



  3. Copy the example Python code for plotting a sine wave listed below and paste it into the sine_wave notebook to the right of where it says In [1]: using the keyboard combination Ctrl+V. Paste the whole code block together, not one line at a time.



    import matplotlib.pyplot as plt  
    import numpy as np

    t = np.arange(0.0, 2.0, 0.01)
    s = np.sin(2*np.pi*t)
    plt.plot(t, s)

    plt.xlabel('time (s)')
    plt.ylabel('voltage (mV)')
    plt.title('voltage (mV) vs. time (sec)')
    plt.grid(True)
    plt.savefig("plot-voltage-vs.-time.png")
    plt.show()


    plt.savefig("plot-voltage-vs.-time.png") saves an image of your plot without all the extra window chrome in your Home directory.



  4. Click the black triangular-shaped Run button ( ) on the menu bar to run the code block.



  5. Your output plot will appear in a small popup window that looks like the popup window in the below screenshot.



    IMG:




  6. Repeat steps 3. and 4. to run a new code block (In [2]:). Try pasting the following simple Python code after In [2]: and running it.



    import matplotlib.pyplot as plt  
    import numpy as np

    x = np.arange(0.0, 2.0, 0.01)
    y = np.sin(2*np.pi*x)
    plt.plot(x, y)
    plt.show()



The error message ImportError: No module named 'matplotlib' was caused by using Python 3 with Jupyter that was installed for Python 2.x. It is possible to use Python 3 in Jupyter Notebook for Python 2 by adding the kernel for Python 2. If you're running Jupyter on Python 3, you can set up a Python 2 kernel like this:



python2 -m pip install ipykernel
python2 -m ipykernel install --user






share|improve this answer














share|improve this answer



share|improve this answer








edited May 22 '18 at 21:24

























answered Nov 3 '16 at 15:03









karelkarel

57.8k12128146




57.8k12128146













  • Hey. First thank you a lot for your answer. I am trying to do that, but when i type the code and run it, i get an Error . It says at the End: "ImportError: no module named "matplotlib" What can i do?

    – Stap Denisov
    Nov 22 '16 at 13:22













  • 1. Check if the python-matplotlib package is installed. 2. If you are using Jupyter, the first line of code to enable plotting in the current Notebook needs to be %matplotlib inline

    – karel
    Nov 22 '16 at 15:19











  • 1. i did that in the console: sudo apt-get install python-matplotlib. I guess that is the matplotib package. 2. Before entering the code in jupyter i typed "%matplotlib inline" in In[1 ]. After running this line i get the same error``???

    – Stap Denisov
    Nov 22 '16 at 15:31













  • I installed Jupyter Notebook and ran the code from my answer and it worked fine in my Jupyter Notebook, so I know that the code is OK. I installed Jupyter Notebook by following these instructions: askubuntu.com/questions/847263/…

    – karel
    Nov 22 '16 at 16:00













  • i think that the code is ok. And i installed jupyter the same way. but why do i get this error, when i already installed matplotlib...?? (ImportError: No module named "matplotlib")

    – Stap Denisov
    Nov 22 '16 at 17:21



















  • Hey. First thank you a lot for your answer. I am trying to do that, but when i type the code and run it, i get an Error . It says at the End: "ImportError: no module named "matplotlib" What can i do?

    – Stap Denisov
    Nov 22 '16 at 13:22













  • 1. Check if the python-matplotlib package is installed. 2. If you are using Jupyter, the first line of code to enable plotting in the current Notebook needs to be %matplotlib inline

    – karel
    Nov 22 '16 at 15:19











  • 1. i did that in the console: sudo apt-get install python-matplotlib. I guess that is the matplotib package. 2. Before entering the code in jupyter i typed "%matplotlib inline" in In[1 ]. After running this line i get the same error``???

    – Stap Denisov
    Nov 22 '16 at 15:31













  • I installed Jupyter Notebook and ran the code from my answer and it worked fine in my Jupyter Notebook, so I know that the code is OK. I installed Jupyter Notebook by following these instructions: askubuntu.com/questions/847263/…

    – karel
    Nov 22 '16 at 16:00













  • i think that the code is ok. And i installed jupyter the same way. but why do i get this error, when i already installed matplotlib...?? (ImportError: No module named "matplotlib")

    – Stap Denisov
    Nov 22 '16 at 17:21

















Hey. First thank you a lot for your answer. I am trying to do that, but when i type the code and run it, i get an Error . It says at the End: "ImportError: no module named "matplotlib" What can i do?

– Stap Denisov
Nov 22 '16 at 13:22







Hey. First thank you a lot for your answer. I am trying to do that, but when i type the code and run it, i get an Error . It says at the End: "ImportError: no module named "matplotlib" What can i do?

– Stap Denisov
Nov 22 '16 at 13:22















1. Check if the python-matplotlib package is installed. 2. If you are using Jupyter, the first line of code to enable plotting in the current Notebook needs to be %matplotlib inline

– karel
Nov 22 '16 at 15:19





1. Check if the python-matplotlib package is installed. 2. If you are using Jupyter, the first line of code to enable plotting in the current Notebook needs to be %matplotlib inline

– karel
Nov 22 '16 at 15:19













1. i did that in the console: sudo apt-get install python-matplotlib. I guess that is the matplotib package. 2. Before entering the code in jupyter i typed "%matplotlib inline" in In[1 ]. After running this line i get the same error``???

– Stap Denisov
Nov 22 '16 at 15:31







1. i did that in the console: sudo apt-get install python-matplotlib. I guess that is the matplotib package. 2. Before entering the code in jupyter i typed "%matplotlib inline" in In[1 ]. After running this line i get the same error``???

– Stap Denisov
Nov 22 '16 at 15:31















I installed Jupyter Notebook and ran the code from my answer and it worked fine in my Jupyter Notebook, so I know that the code is OK. I installed Jupyter Notebook by following these instructions: askubuntu.com/questions/847263/…

– karel
Nov 22 '16 at 16:00







I installed Jupyter Notebook and ran the code from my answer and it worked fine in my Jupyter Notebook, so I know that the code is OK. I installed Jupyter Notebook by following these instructions: askubuntu.com/questions/847263/…

– karel
Nov 22 '16 at 16:00















i think that the code is ok. And i installed jupyter the same way. but why do i get this error, when i already installed matplotlib...?? (ImportError: No module named "matplotlib")

– Stap Denisov
Nov 22 '16 at 17:21





i think that the code is ok. And i installed jupyter the same way. but why do i get this error, when i already installed matplotlib...?? (ImportError: No module named "matplotlib")

– Stap Denisov
Nov 22 '16 at 17:21


















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%2f845111%2fplot-simple-functions-like-sine-of-x-with-ipython%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

How to change which sound is reproduced for terminal bell?

Can I use Tabulator js library in my java Spring + Thymeleaf project?

Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents