1

I tried running plt.show() but no plot is shown. I had tried lots of solutions from stackoverflow including setting matplotlib backend to Qt4Agg, switching to other backends (i.e. TkAgg, Agg) and reinstalling matplotlib package but still not solving the issue. Some solutions that I had tried but not working are:

matplotlib does not show my drawings although I call pyplot.show()

Matplotlib.Pyplot does not show output; No Error

Why matplotlib does not plot?

Matplotlib does not show labels or numbers

Below is the code that I tried to run:

plt.scatter(pf["age"], pf["friend_count"])
plt.xlabel = "age"
plt.ylabel = "friends count"
plt.title = "Facebook Friends count by Age"
plt.show()

When plt.scatter(pf["age"], pf["friend_count"]) code was run, a scatter plot was shown but with no labels and title. Running plt.show() did not plot and no error was shown. Appreciate any help.

I installed Anaconda with Python 3 for Windows OS. My Mac laptop is running on Bootcamp.

2
  • What are you running your Python code in: PyCharm, Spyder, Canopy, Jupyter notebook, iPython, the Terminal? Commented Jun 23, 2016 at 3:55
  • I run the original code in both Spyder and Jupyter notebook and get the same result. I tried your code in both Spyder and Jupyter too. Spyder produces similar result but Jupyter hangs (the plot on a new window is not responding). Commented Jun 23, 2016 at 4:06

1 Answer 1

2

The labels must use parentheses such as plt.xlabel("text"), not assigned to a string with = like you have in your example code. Make the changes in your code, save the changes, quit and reopen Spyder or whatever interpreter you are running, then run the code again.

plt.figure(1)
plt.scatter(pf["age"], pf["friend_count"])
plt.xlabel("age")
plt.ylabel("friends count")
plt.title("Facebook Friends count by Age")
plt.show()
Sign up to request clarification or add additional context in comments.

2 Comments

Tried your code but it is still not working. a scatter plot was shown with no labels and title. Similar to the original issue, I suspect the scatter plot was shown due to plt.scatter() rather than plt.show()
Thanks. It's working now. what a rookie mistake! Cheers

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.