- Trending Categories
- Data Structure
- Operating System
- MS Excel
- C Programming
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to make a scatter plot for clustering in Python?
To make a scatter plot for clustering in Python, we can take the following steps −
- Set the figure size and adjust the padding between and around the subplots.
- Create x and y data points, Cluster and centers using numpy.
- Create a new figure or activate an existing figure.
- Add a subplot arrangement to the current figure.
- Plot the scatter data points using scatter() method.
- Iterate centers data and place marker using scatter() method.
- To display the figure, use show() method.
import numpy as np import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True x = np.random.randn(10) y = np.random.randn(10) Cluster = np.array([0, 1, 1, 1, 3, 2, 2, 3, 0, 2]) centers = np.random.randn(4, 2) fig = plt.figure() ax = fig.add_subplot(111) scatter = ax.scatter(x, y, c=Cluster, s=50) for i, j in centers: ax.scatter(i, j, s=50, c='red', marker='+') plt.show()
It will produce the following output
- Related Articles
- How to make a 3D scatter plot in Python?
- How to make a discrete colorbar for a scatter plot in matplotlib?
- Python - Draw a Scatter Plot for a Pandas DataFrame
- How to overplot a line on a scatter plot in Python?
- How can I make a scatter plot colored by density in Matplotlib?
- How to draw an average line for a scatter plot in MatPlotLib?
- How to animate a scatter plot in Matplotlib?
- Python Scatter Plot with Multiple Y values for each X
- How can Seaborn library be used to display a Scatter Plot in Python?
- Python Plotly – How to simultaneously apply color/shape/size in a Scatter Plot?
- Scatter plot and Color mapping in Python
- How to use different markers for different points in a Pylab scatter plot(Matplotlib)?
- Create a Scatter Plot with SeaBorn – Python Pandas
- Python Plotly – How to manually set the color of points in a scatter plot?
- How can Bokeh be used to generate scatter plot using Python?