Skip to content

Instantly share code, notes, and snippets.

@sinhrks
Created March 16, 2014 06:29
Show Gist options
  • Save sinhrks/9579355 to your computer and use it in GitHub Desktop.
Save sinhrks/9579355 to your computer and use it in GitHub Desktop.
Squarify plot example
import squarify
import matplotlib.pyplot as plt
from numpy.random import rand
fig, axes = plt.subplots(2, 3, figsize=(14, 8))
plt.subplots_adjust(top=0.95, bottom=0.05, left=0.05, right=0.95, hspace=0.35)
sq = 8
def random_colors(n):
return zip(rand(n), rand(n), rand(n))
labels = ['Sq{0}'.format(i) for i in range(sq)]
axes[0, 0].set_title('Default')
squarify.plot(rand(sq), ax=axes[0, 0])
axes[0, 1].set_title('Specify single color')
squarify.plot(rand(sq), color='r', ax=axes[0, 1])
axes[0, 2].set_title('Specify each colors')
squarify.plot(rand(sq), color=random_colors(sq), ax=axes[0, 2])
axes[1, 0].set_title('Specify labels')
squarify.plot(rand(sq), label=labels, ax=axes[1, 0])
sizes = rand(sq)
values = ['{0:0.2f}'.format(s) for s in sizes]
axes[1, 1].set_title('Specify values')
squarify.plot(sizes, value=values, ax=axes[1, 1])
axes[1, 2].set_title('Specify labels and values')
squarify.plot(sizes, label=labels, value=values, ax=axes[1, 2])
plt.show()
@sinhrks
Copy link
Author

sinhrks commented Mar 16, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment