Reputation: 17
https://www.youtube.com/watch?v=pl3D4SosO_4&list=PL9mhv0CavXYjiIniCLj_5KKN58PaxJBVj&index=2
Right at time stamp 2:13.
I am trying to follow a youtube tutorial and I have hit a road block. There is no documentation online that tells me how to implement matplotlib.collections.PathCollection
The youtuber in this video that I am following runs the first bit of his code (at about 2:13) and a plot appears with some color data points. Above this plot it says <matplotlib.collections.PathCollection at 0x208cd62cef0>
If anyone could tell me how this youtuber got this plot to appear I would be forever grateful.
I have found documentation for matplotlib.collections, but zero information on how it is used, I asked the youtuber how he got to this point in the comments and am waiting on an answer.
Thank you Craig, I am adding the code that doesn't work for me here
EDIT: (I have been attempting this in a pycharm IDE and the video is using Jupyter, idk if that makes a difference)
import numpy as np
from matplotlib import plyplot as plt
from sklearn.datasets import make_blobs
X,y = make_blobs(n_samples = 500, centers = 5, random_state = 3)
plt.figure(0)
plt.grid(True)
plt.scatter(X[:,0], X[:,1],c=y)
when this is run in the video a plot with color clusters appears.
Maybe I should be trying this in jupyter, maybe some image libraries are pre-loaded there?
Upvotes: 0
Views: 4373
Reputation: 4855
Jupyter is a special interactive environment and it automatically renders matplotlib plots when it runs a cell that creates a plot. If you are doing the same thing in an IDE, then you will need to explicitly render the plot by calling plt.show()
when you want the plot to appear. You can do this for your code by adding it to the end:
import numpy as np
from matplotlib import plyplot as plt
from sklearn.datasets import make_blobs
X,y = make_blobs(n_samples = 500, centers = 5, random_state = 3)
plt.figure(0)
plt.grid(True)
plt.scatter(X[:,0], X[:,1],c=y)
plt.show() # <-- show the plot
Upvotes: 1