%matplotlib inline SyntaxError: invalid syntax

0 votes

I have the following code snippet:

%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
$ python test.py
  File "test.py", line 1
    %matplotlib inline
    ^
SyntaxError: invalid syntax

It throws a syntax error. What do I do?

Aug 1, 2019 in Python by Ajay

edited Jun 25 by MD 8,128 views
how to rectify this error?
@Merlin's suggestion did not work for you?

2 answers to this question.

0 votes

If you're using Jupyter notebook, just mention this line int he first cell. This syntax works on the Jupyter Notebook.

In []: %matplotlib inline

This is a really good command and works best with Jupiter's IPython Notebook. Its basically used to show an image automatically within the browser without using show().

But in your python script, you can't use this syntax. You can eliminate the use of this function completely and replace it with the bellow code:

import matplotlib.pyplot as plt
new_obj.resample('M').sum().plot(kind="bar")
plt.show()
answered Aug 1, 2019 by Merlin

edited Jun 25 by MD
0 votes
I found a good solution to solve the problem, in this web address https://zhuanlan.zhihu.com/p/34948525
answered May 2 by Edu

Related Questions In Python

0 votes
1 answer

Python error "SyntaxError: invalid syntax"

but i m getting this ouput: Enter the ...READ MORE

answered Mar 20 in Python by anonymous
4,505 views
0 votes
1 answer

SyntaxError: invalid syntax print worldlists[len(words)]

Hi@akhtar, This syntax will not allow in all ...READ MORE

answered Jun 30 in Python by MD
• 43,400 points
73 views
0 votes
1 answer

'Syntax Error: invalid syntax' for no apparent reason

You're missing a close paren in this ...READ MORE

answered Aug 13, 2018 in Python by Priyaj
• 57,550 points
561 views
0 votes
1 answer

What exactly is invalid syntax error?

please solve this error   def TakeImages():     Id=(text.get())   ...READ MORE

answered Jul 20 in Python by Prince kumar
288 views
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 1,213 views
0 votes
0 answers
+4 votes
6 answers
+1 vote
6 answers
0 votes
1 answer

How to write inline if statement for print in Python?

Inline if-else expression must always contain the else ...READ MORE

answered Dec 4, 2018 in Python by Nymeria
• 3,520 points

edited Dec 6, 2018 by Nymeria 6,840 views