Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

>>> %matplotlib inline results in SyntaxError: invalid syntax

1,121 views
Skip to first unread message

Mike S

unread,
Jan 29, 2016, 2:04:47 AM1/29/16
to
I have installed Python 3.4.4 on XPSP3 and am trying to work my way
through this tutorial.

A Complete Tutorial on Ridge and Lasso Regression in Python
http://www.analyticsvidhya.com/blog/2016/01/complete-tutorial-ridge-lasso-regression-python/

In Step 2 "Why Penalize the Magnitude of Coefficients?" we are shown
this code:

#Importing libraries. The same will be used throughout the article.
import numpy as np
import pandas as pd
import random
import matplotlib.pyplot as plt
%matplotlib inline

I get an error on the last line. I am running this code in Idle Python
3.4.4 Shell...

Python 3.4.4 (v3.4.4:737efcadf5a6, Dec 20 2015, 19:28:18) [MSC v.1600 32
bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> import numpy as np
>>> import pandas as pd
>>> import random
>>> import matplotlib.pyplot as plt
>>> %matplotlib inline
SyntaxError: invalid syntax

What am I doing wrong? Suggested reading?
TIA,
Mike

Chris Angelico

unread,
Jan 29, 2016, 2:33:16 AM1/29/16
to
On Fri, Jan 29, 2016 at 6:04 PM, Mike S via Python-list
<pytho...@python.org> wrote:
>
> I get an error on the last line. I am running this code in Idle Python 3.4.4
> Shell...
>
> Python 3.4.4 (v3.4.4:737efcadf5a6, Dec 20 2015, 19:28:18) [MSC v.1600 32 bit
> (Intel)] on win32
> Type "copyright", "credits" or "license()" for more information.
>>>> import numpy as np
>>>> import pandas as pd
>>>> import random
>>>> import matplotlib.pyplot as plt
>>>> %matplotlib inline
> SyntaxError: invalid syntax
>
> What am I doing wrong? Suggested reading?

That's a magic command for ipython - it's not actual Python syntax.
You can either install ipython and do the exercises there, or continue
with Idle and accept that things will be slightly different. Skim
through a few more of the examples; do you see more lines starting
with percent signs? If not, you can probably get away with using any
interactive Python interpreter (including Idle as you're using above).
Alternatively, take the certain route and install ipython - then
everything should work.

ChrisA

Steven D'Aprano

unread,
Jan 29, 2016, 2:57:46 AM1/29/16
to
On Fri, 29 Jan 2016 06:04 pm, Mike S wrote:

> %matplotlib inline
>
> I get an error on the last line. I am running this code in Idle Python
> 3.4.4 Shell...
>
> Python 3.4.4 (v3.4.4:737efcadf5a6, Dec 20 2015, 19:28:18) [MSC v.1600 32
> bit (Intel)] on win32
> Type "copyright", "credits" or "license()" for more information.
> >>> import numpy as np
> >>> import pandas as pd
> >>> import random
> >>> import matplotlib.pyplot as plt
> >>> %matplotlib inline
> SyntaxError: invalid syntax
>
> What am I doing wrong? Suggested reading?

That %matplotlib looks to me like iPython "magic" -- yes, that's the
official name for it. It's not real Python code, and won't run in a regular
Python interpreter like IDLE.

IPython is a custom Python interactive interpreter. As well as running
regular Python code, it includes special syntax for magic such as:

%cd
%run
%bg

and many more.

http://ipython.org/ipython-doc/rel-0.10.2/html/interactive/reference.html#magic

You could try installing iPython and running the tutorial examples in that,
or perhaps finding a better tutorial that actually bothers to mention what
it needs to run.

(You have read the tutorial from the beginning, yes?)




--
Steven

Mike S

unread,
Jan 29, 2016, 3:11:09 AM1/29/16
to
Thank you Chris and Steven, I'll see if I can get iPython running and do
a tutorial.

Message has been deleted

kaif khan

unread,
Oct 4, 2022, 7:53:28 AM10/4/22
to
Try setting up iPython and using that to run the tutorial examples, or look for a better tutorial that actually tries to describe what it requires to run.
for more info. visit https://brainalyst.in/

Edmondo Giovannozzi

unread,
Oct 4, 2022, 8:02:25 AM10/4/22
to
Il giorno martedì 4 ottobre 2022 alle 13:53:28 UTC+2 kaif khan ha scritto:
> Try setting up iPython and using that to run the tutorial examples, or look for a better tutorial that actually tries to describe what it requires to run.
> for more info. visit https://brainalyst.in/

By the way, I don't like matplotlib inline as one cannot interact with the figure like zooming or panning, etc. Typically, I disable that feature in spyder.

alpha edge

unread,
May 13, 2023, 9:24:05 AM5/13/23
to

alpha edge

unread,
May 26, 2023, 3:04:26 AM5/26/23
to

risky sibam

unread,
Jun 11, 2023, 6:25:28 AM6/11/23
to
http://journal.poltekkesjambi.ac.id/inc.php?tunnel=yowestogel
http://journal.poltekkesjambi.ac.id/inc.php?tunnel=mahajitu
http://journal.poltekkesjambi.ac.id/inc.php?tunnel=bos88
http://journal.poltekkesjambi.ac.id/inc.php?tunnel=toto855
http://journal.poltekkesjambi.ac.id/inc.php?tunnel=sirmenang
http://journal.poltekkesjambi.ac.id/inc.php?tunnel=ihokibet
http://journal.poltekkesjambi.ac.id/inc.php?tunnel=redwin69
http://journal.poltekkesjambi.ac.id/inc.php?tunnel=ino777
http://journal.poltekkesjambi.ac.id/inc.php?tunnel=pohon4d
http://journal.poltekkesjambi.ac.id/inc.php?tunnel=bwinbet365
http://journal.poltekkesjambi.ac.id/inc.php?tunnel=pintutogel
http://journal.poltekkesjambi.ac.id/inc.php?tunnel=grup123
http://journal.poltekkesjambi.ac.id/inc.php?tunnel=poka88
http://journal.poltekkesjambi.ac.id/inc.php?tunnel=bento4d
http://journal.poltekkesjambi.ac.id/inc.php?tunnel=surgawin
http://journal.poltekkesjambi.ac.id/inc.php?tunnel=radiumplay
http://journal.poltekkesjambi.ac.id/inc.php?tunnel=wings365
http://journal.poltekkesjambi.ac.id/inc.php?tunnel=gbo303
http://journal.poltekkesjambi.ac.id/inc.php?tunnel=sis4d
http://journal.poltekkesjambi.ac.id/inc.php?tunnel=bidadari29
http://journal.poltekkesjambi.ac.id/inc.php?tunnel=happybet
http://journal.poltekkesjambi.ac.id/inc.php?tunnel=ultra88
http://journal.poltekkesjambi.ac.id/inc.php?tunnel=elangwin
http://journal.poltekkesjambi.ac.id/inc.php?tunnel=bungaslot
http://journal.poltekkesjambi.ac.id/inc.php?tunnel=bobatoto
http://journal.poltekkesjambi.ac.id/inc.php?tunnel=surya303
http://journal.poltekkesjambi.ac.id/inc.php?tunnel=merdeka138
http://journal.poltekkesjambi.ac.id/inc.php?tunnel=ligabola
http://journal.poltekkesjambi.ac.id/inc.php?tunnel=lele247
http://journal.poltekkesjambi.ac.id/inc.php?tunnel=sekar4d
http://journal.poltekkesjambi.ac.id/inc.php?tunnel=macau303
http://journal.poltekkesjambi.ac.id/inc.php?tunnel=petir99
http://journal.poltekkesjambi.ac.id/inc.php?tunnel=fun77toto
http://journal.poltekkesjambi.ac.id/inc.php?tunnel=slotjitu
http://journal.poltekkesjambi.ac.id/inc.php?tunnel=lgogacor
http://journal.poltekkesjambi.ac.id/inc.php?tunnel=mpotower
http://journal.poltekkesjambi.ac.id/inc.php?tunnel=ktvtogel
http://journal.poltekkesjambi.ac.id/inc.php?tunnel=vip138
http://journal.poltekkesjambi.ac.id/inc.php?tunnel=rtp kaskustoto
http://journal.poltekkesjambi.ac.id/inc.php?tunnel=toko4d
http://journal.poltekkesjambi.ac.id/inc.php?tunnel=gagah4d
http://journal.poltekkesjambi.ac.id/inc.php?tunnel=primerplay
http://journal.poltekkesjambi.ac.id/inc.php?tunnel=dragon303
http://journal.poltekkesjambi.ac.id/inc.php?tunnel=kakekqq
http://journal.poltekkesjambi.ac.id/inc.php?tunnel=gitar100jt
http://journal.poltekkesjambi.ac.id/inc.php?tunnel=kuatjp
http://journal.poltekkesjambi.ac.id/inc.php?tunnel=gacor69
http://journal.poltekkesjambi.ac.id/inc.php?tunnel=vegas338
http://journal.poltekkesjambi.ac.id/inc.php?tunnel=fastwin77
http://journal.poltekkesjambi.ac.id/inc.php?tunnel=titanslot88
http://journal.poltekkesjambi.ac.id/inc.php?tunnel=agen288
http://journal.poltekkesjambi.ac.id/inc.php?tunnel=axiata4d
http://journal.poltekkesjambi.ac.id/inc.php?tunnel=sempatigame
http://journal.poltekkesjambi.ac.id/inc.php?tunnel=mpoyes
http://journal.poltekkesjambi.ac.id/inc.php?tunnel=ml138
http://journal.poltekkesjambi.ac.id/inc.php?tunnel=gg178
http://journal.poltekkesjambi.ac.id/inc.php?tunnel=totojitu
http://journal.poltekkesjambi.ac.id/inc.php?tunnel=rtp neng4d
http://journal.poltekkesjambi.ac.id/inc.php?tunnel=ronaldoslot
http://journal.poltekkesjambi.ac.id/inc.php?tunnel=playbet88
http://journal.poltekkesjambi.ac.id/inc.php?tunnel=ekotogel
http://journal.poltekkesjambi.ac.id/inc.php?tunnel=cuan55
http://journal.poltekkesjambi.ac.id/inc.php?tunnel=otoslot
http://journal.poltekkesjambi.ac.id/inc.php?tunnel=sultan899
http://journal.poltekkesjambi.ac.id/inc.php?tunnel=selamatjudi
http://journal.poltekkesjambi.ac.id/inc.php?tunnel=nagadewa
http://journal.poltekkesjambi.ac.id/inc.php?tunnel=899sport
http://journal.poltekkesjambi.ac.id/inc.php?tunnel=lapak77
http://journal.poltekkesjambi.ac.id/inc.php?tunnel=vistatoto
http://journal.poltekkesjambi.ac.id/inc.php?tunnel=rtp mawartoto
http://journal.poltekkesjambi.ac.id/inc.php?tunnel=ebobet
http://journal.poltekkesjambi.ac.id/inc.php?tunnel=tobabet88
http://journal.poltekkesjambi.ac.id/inc.php?tunnel=king177
http://journal.poltekkesjambi.ac.id/inc.php?tunnel=suhuslot88
http://journal.poltekkesjambi.ac.id/inc.php?tunnel=togaplay
http://journal.poltekkesjambi.ac.id/inc.php?tunnel=poin123
http://journal.poltekkesjambi.ac.id/inc.php?tunnel=rajaslot303
http://journal.poltekkesjambi.ac.id/inc.php?tunnel=liga138
http://journal.poltekkesjambi.ac.id/inc.php?tunnel=bet777
http://journal.poltekkesjambi.ac.id/inc.php?tunnel=tangandewa
http://journal.poltekkesjambi.ac.id/inc.php?tunnel=intan123
http://journal.poltekkesjambi.ac.id/inc.php?tunnel=bbm4d
http://journal.poltekkesjambi.ac.id/inc.php?tunnel=menara3388
http://journal.poltekkesjambi.ac.id/inc.php?tunnel=havana88
http://journal.poltekkesjambi.ac.id/inc.php?tunnel=ubo4d
http://journal.poltekkesjambi.ac.id/inc.php?tunnel=cerah88
http://journal.poltekkesjambi.ac.id/inc.php?tunnel=ada303
http://journal.poltekkesjambi.ac.id/inc.php?tunnel=bandarsloto
http://journal.poltekkesjambi.ac.id/inc.php?tunnel=indoslots
http://journal.poltekkesjambi.ac.id/inc.php?tunnel=istana777
http://journal.poltekkesjambi.ac.id/inc.php?tunnel=kompastoto
http://journal.poltekkesjambi.ac.id/inc.php?tunnel=rtp inatogel
http://journal.poltekkesjambi.ac.id/inc.php?tunnel=jp88
http://journal.poltekkesjambi.ac.id/inc.php?tunnel=rtp ugdewa
http://journal.poltekkesjambi.ac.id/inc.php?tunnel=rtp angsa4d
http://journal.poltekkesjambi.ac.id/inc.php?tunnel=bobaslot
http://journal.poltekkesjambi.ac.id/inc.php?tunnel=toto12
http://journal.poltekkesjambi.ac.id/inc.php?tunnel=orbit88
http://journal.poltekkesjambi.ac.id/inc.php?tunnel=mgo77
http://journal.poltekkesjambi.ac.id/inc.php?tunnel=hoki168

Geetanjali Care

unread,
Dec 21, 2023, 1:48:14 AM12/21/23
to
https://smartworlddxp.com/
https://landmarkspringwalk.co.in/
https://ocusmedley.com/
https://reach3roads.co.in/
https://sawasdee18delhi.in/
https://sawasdeegems.com/
https://sawasdeenoveltystreet.com/
https://sawasdeensp.co/
https://bhutanietherea.in/
https://bhutaniavenue.in/
https://alphathumfoodcourt.com/
https://cyberthumcourtyard.com/
https://bhutani150.in/
https://vatikacrossover.co.in/
https://capitaloneglobal73.com/
https://paras114.com/
https://mapskoasprhill.co.in/
https://estate95.in/
https://pyramidpalmcounty.co/
https://vatikaxpressions.co.in/
https://tarcdelhi.com/
https://adoretheselectpremia.com/
https://navrajtheantalyas37.com/
https://silvergladeshightown.co.in/
https://svh83.com/
https://manishgallexie91.co.in/
https://migsunrohini.co.in/
https://bhutanigoavilla.com/
https://32ndbeachside.com/
https://cyberthummypod.com/
https://royalgreencourtyard37.in/
https://royalgreencourtyard62.com/
https://orrisgateway.com/
https://bptpamstoria.in/
https://bptpastairegardens.in/
https://robo-g.com/
https://galaexpo.in/
https://amarylliunitygroup.com/
https://gurugramresidentialproperties.com/
https://ameyasapphire57.co.in/
https://tulipmonsella53.in/
https://vsrparkstreet.com/
https://ambiencecaitriona.co.in/
https://parasquartier.co/
https://glsavenue.com/
https://pyramid71.net/
https://axongoa.com/
https://isprava.co/
https://rahejamall.com/
https://32ndryu.com/
https://bhutani133.in/
https://133avenue.in/
https://yashika109.com/
https://adani62.com/
https://vatikahorizon82.co.in/
https://signatureglobal37.in/
https://signatureglobal88a.co.in/
https://rahejavanya.in/
https://m3mparagon.co/
https://gangareality84.com/
https://32ndparisdream.com/
https://omaxehistreet.co.in/
https://irisbroadway85.com/
https://migsunjanpath.co/
https://aisthegalleria.in/
https://sayastatus129.in/
https://sikkamallnoida.com/
https://paras133.com/
https://gygynoida.in/
https://geetanjalihomestate.co.in/ais-the-galleria-gomti-nagar-extension-lucknow
https://geetanjalihomestate.co.in/blogs/ganga-realty-luxurious-3bhk-4bhk-apartments
https://geetanjalihomestate.co.in/dlf-privana-sector-77-gurgaon
https://geetanjalihomestate.co.in/omaxe-hi-street-kalli-pashchim-lucknow
https://geetanjalihomestate.co.in/migsun-janpath-sushant-golf-city-lucknow
https://geetanjalihomestate.co.in/suncity-platinum-towers
https://geetanjalihomestate.co.in/dlf-the-crest-sector-54-gurgaon
https://geetanjalihomestate.co.in/ascott-ireo-city-sector-59-gurgaon
https://geetanjalihomestate.co.in/commercial-property-in-lucknow.php
https://geetanjalihomestate.co.in/residential-property-in-gurgaon.php
https://walstreet73.com/
https://paras114.com/
https://skybhutanialphathum.in/
https://cybercourtyard.co.in/
https://bhutanialphathum.co/
https://grandvista73.com/
https://reachcomercia.com/
https://32ndavenuemilestone.in/
https://breezfloraavenue88.com/
https://vatikavlante.com/
https://herohomes85.com/
https://sbtlgateway95.co.in/
https://reachmytower.com/
https://adoretheselectpremia.com/
https://centralparkorchard.org/
https://chintel109.com/
https://mrgtheskyline.com/
https://mrgtheultimus.com/
https://mrgcrown106.net/
https://mrgthemeridian.com/
https://supernovaspira.in/
https://vatikaaspiration.com/

Geetanjali Care

unread,
Dec 21, 2023, 1:50:25 AM12/21/23
to

Geetanjali Care

unread,
Dec 22, 2023, 12:08:27 AM12/22/23
to
On Tuesday, October 4, 2022 at 5:23:28 PM UTC+5:30, kaif khan wrote:
> Try setting up iPython and using that to run the tutorial examples, or look for a better tutorial that actually tries to describe what it requires to run.
> for more info. visit https://brainalyst.in/
Best residential property in noida:
https://experion45noida.in/

geetanajali homes

unread,
Dec 25, 2023, 12:34:57 AM12/25/23
to

Alan Gauld

unread,
Dec 25, 2023, 2:53:22 PM12/25/23
to
On 25/12/2023 05:34, geetanajali homes via Python-list wrote:

>> import numpy as np
>> import pandas as pd
>> import random
>> import matplotlib.pyplot as plt
>> %matplotlib inline
>>
>> I get an error on the last line. I am running this code in Idle Python
>> 3.4.4 Shell...

Python names can't start with a % (its the modulo or
string formatting operator).

I know nothing of the innards of matplotlib so I can only
suggest a closer examination of their tutorial information.

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


Chris Grace

unread,
Dec 25, 2023, 3:26:54 PM12/25/23
to
"%matplotlib inline" is a magic command that changes how plots render when
working with IPython. Read more here: https://stackoverflow.com/a/43028034

The article you linked assumes you are working in an IPython shell, not
IDLE. This is common in the data science world.

You may already have IPython installed. Try running it from a command line
with `python -m IPython`. If that doesn't work, you can first install it
with `python -m pip install IPython`, then run the 1st command.

IPython is commonly used as a Jupyter Notebook kernel. See
https://jupyter-notebook-beginner-guide.readthedocs.io/en/latest/index.html
for more information about Jupyter Notebook.

I'd also recommend a newer version of python. Python 3.4 reached end of
life almost 5 years ago. Some of the packages used in the linked article no
longer officially support python 3.4. That doesn't necessarily mean that
you'll experienced issues using python 3.4, but much has changed in the 7
years since that article was written.

On Mon, Dec 25, 2023, 2:53 PM Alan Gauld via Python-list <
pytho...@python.org> wrote:

> On 25/12/2023 05:34, geetanajali homes via Python-list wrote:
>
> >> import numpy as np
> >> import pandas as pd
> >> import random
> >> import matplotlib.pyplot as plt
> >> %matplotlib inline
> >>
> >> I get an error on the last line. I am running this code in Idle Python
> >> 3.4.4 Shell...
>
> Python names can't start with a % (its the modulo or
> string formatting operator).
>
> I know nothing of the innards of matplotlib so I can only
> suggest a closer examination of their tutorial information.
>
> --
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
> http://www.amazon.com/author/alan_gauld
> Follow my photo-blog on Flickr at:
> http://www.flickr.com/photos/alangauldphotos
>
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>

Chris Angelico

unread,
Dec 25, 2023, 3:33:02 PM12/25/23
to
On Tue, 26 Dec 2023 at 07:27, Chris Grace via Python-list
<pytho...@python.org> wrote:
> I'd also recommend a newer version of python. Python 3.4 reached end of
> life almost 5 years ago.

Uhh, putting this in perspective... until a spammer revived the thread
just now, it was asked, answered, and finished with, all back in 2016.

I don't think anyone's still waiting on answers here.

ChrisA

MRAB

unread,
Dec 25, 2023, 3:45:10 PM12/25/23
to
On 2023-12-25 19:53, Alan Gauld via Python-list wrote:
> On 25/12/2023 05:34, geetanajali homes via Python-list wrote:
>
>>> import numpy as np
>>> import pandas as pd
>>> import random
>>> import matplotlib.pyplot as plt
>>> %matplotlib inline
>>>
>>> I get an error on the last line. I am running this code in Idle Python
>>> 3.4.4 Shell...
>
> Python names can't start with a % (its the modulo or
> string formatting operator).
>
> I know nothing of the innards of matplotlib so I can only
> suggest a closer examination of their tutorial information.
>
I believe it's a feature of Jupyter specifically. It won't work in IDLE.
0 new messages