%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 9,238 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
5,132 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
• 57,060 points
106 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,660 points
677 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
330 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,363 views
0 votes
0 answers
+4 votes
6 answers

Lowercase in Python

You can simply the built-in function in ...READ MORE

answered Apr 11, 2018 in Python by hemant
• 5,800 points
1,011 views
+1 vote
8 answers

How to fix this? ValueError: invalid literal for int() with base 10 error in Python

Just for the record: >>> int('55063.000000') Traceback (most recent ...READ MORE

answered Aug 17 in Python by pakainfo
• 200 points
149,230 views
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 8,110 views