0

I'm plotting some tree maps using squarify.

I can't figure out how to define figsize for them though, nor I can find anything in their docs. Below the working code:

df = df.groupby(feature)["profit"].sum()
squarify.plot(sizes=df, label=df.index, alpha=.8)
plt.axis('off')
plt.show()

I've tried to add figsize=(14, 6) to squarify.plot as you can see below, but didn't work.

squarify.plot(sizes=df, label=df.index, figsize=(14, 6), alpha=.8)

I appreciate the help.

warped
  • 8,947
  • 3
  • 22
  • 49
42piratas
  • 555
  • 1
  • 9
  • 26

1 Answers1

1

The source of the plot function looks like this:

def plot(
    sizes,
    norm_x=100,
    norm_y=100,
    color=None,
    label=None,
    value=None,
    ax=None,
    pad=False,
    bar_kwargs=None,
    text_kwargs=None,
    **kwargs
):

So the function takes an ax argument, which you can generate like this:

fig = plt.figure(figsize=(14,6))
ax = fig.add_suplot(111)

then

squarify.plot(sizes=df, ax=ax)
warped
  • 8,947
  • 3
  • 22
  • 49
  • Thank you! But now I'm intrigued with something else. What's the trick with "111"? I've just looked at the docs and have seen the use of "111" there as well, but can't get it by the explanation of the parameters – 42piratas Jan 23 '21 at 14:40
  • 1
    [Check this](https://matplotlib.org/3.1.1/api/_as_gen/matplotlib.pyplot.subplot.html). 111 is shorthand for 1,1,1. This means you create a grid with 1 row, 1 column and go to the first plot, which in this case is the only one. 2,2,2 would mean you create a grid with 2 rows, 2 columns and go to plot 2, which is top-right – warped Jan 23 '21 at 14:44
  • 1
    Also, check [this post](https://stackoverflow.com/questions/3584805/in-matplotlib-what-does-the-argument-mean-in-fig-add-subplot111) – warped Jan 23 '21 at 14:46