Created
March 16, 2014 06:29
-
-
Save sinhrks/9579355 to your computer and use it in GitHub Desktop.
Squarify plot example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example for
pandas-dev/pandas#6644