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.

Community
  • 1
  • 1
iLoeng
  • 434
  • 1
  • 4
  • 14
  • What are you running your Python code in: PyCharm, Spyder, Canopy, Jupyter notebook, iPython, the Terminal? – wigging Jun 23 '16 at 03: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). – iLoeng Jun 23 '16 at 04:06

1 Answers1

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()
wigging
  • 8,492
  • 12
  • 75
  • 117
  • 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() – iLoeng Jun 23 '16 at 03:55
  • Thanks. It's working now. what a rookie mistake! Cheers – iLoeng Jun 23 '16 at 04:27