0

I have the output of the cluster details as shown below.

from collections import Counter, defaultdict
print(Counter(kmodess.labels_))

Output is the cluster number and number of users belonging to it: Counter({1: 10500, 2: 400, 3:10})

I want to show something like below. Is this possible in Python or if I have to use javascript, how do I proceed with this kind of representation?

enter image description here

I have refered the code from the below matplot.lib link. plot a circle with pyplot

But, how do I give the input and show the circles based on that?

P H
  • 294
  • 1
  • 3
  • 16

2 Answers2

0

If you already know how to do this with pyplot you could save it to a file and serve that statically, no js required.

To dump your plot to a file:

plt.savefig('clusters.png')

Then use an HTML img tag:

<!DOCTYPE html>
<html>
  <head>
    <title>Display my Matplotlib Image</title>
  </head>
  <body>
    <img src="clusters.png" alt="Large and small circles representing clusters">
  </body>
</html>

To see the result, just open the above html file with your browser.

Evan
  • 2,120
  • 1
  • 15
  • 20
  • I tried matplotlib.pyplot. I found a way to represent this using a piechart rather than seperate circles. Thanks so much for your help. – P H Feb 05 '20 at 08:30
0

I found the best way to represent such diagrams using piechart. Below is the link https://matplotlib.org/3.1.1/gallery/pie_and_polar_charts/pie_and_donut_labels.html#sphx-glr-gallery-pie-and-polar-charts-pie-and-donut-labels-py

P H
  • 294
  • 1
  • 3
  • 16