We want to show in this recipe how to solve a "real-world" task—how to use matplotlib to visualize our directory occupancy.
In this recipe, you will learn how to visualize a filesystem tree with relative sizes.
We all have big hard drives that sometimes contain stuff that we usually forget about. It would be nice to see what is inside such a directory, and what the biggest file inside it is.
Although there are many more sophisticated and elaborate software products for this job, we want to demonstrate how this is achievable using Python and matplotlib.
Let's perform the following steps:
Implement a few helper functions to deal with folder discovery and internal data structures.
Implement the main function,
draw()
, that does the plotting.Implement the main program body that verifies the user input arguments:
import os import sys import matplotlib.pyplot as plt import matplotlib.cm as cm import numpy as np def build_folders...