How it works...

The following is the explanation of the preceding code:

  • class Cluster(object): Defines a class named Cluster.
  • ind = 0 initializes the index, which moves back and forth as the prev and next buttons are pressed.
  • def next(self, event): defines the next method as a callback function for the next button:
    • self.ind += 1 increments the index by 1.
    • i = self.ind % len(species) converts the running index to zero, 1, or 2 for the number of clusters in the species.
    • index = iris['species'] == species[i] picks up the indices of the data corresponding to the next cluster.
    • axs.clear() clears previous data on the axes. If we don't do this, all the clusters will be visible on the axis, and only the color of cluster being refreshed will keep ...

Get Matplotlib 3.0 Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.