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, 2020 by MD 25,862 views
how to rectify this error?
@Merlin's suggestion did not work for you?

1 answer 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, 2020 by MD

Related Questions In Python

0 votes
1 answer

SyntaxError: invalid syntax in inline function.

Hi@akhtar, You need to write your if-else code ...READ MORE

answered Oct 5, 2020 in Python by MD
• 95,460 points
1,174 views
0 votes
1 answer

Python error "SyntaxError: invalid syntax"

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

answered Mar 20, 2020 in Python by anonymous
8,327 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, 2020 in Python by MD
• 95,460 points
2,453 views
0 votes
2 answers
+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 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,464 views
0 votes
1 answer
+5 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,790 points
4,123 views
+2 votes
10 answers

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

The following are totally acceptable in python: passing ...READ MORE

answered Nov 16, 2018 in Python by Nymeria
• 3,560 points
409,359 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,560 points

edited Dec 6, 2018 by Nymeria 16,767 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP