Jose: Hi guys, and welcome back.
In this video, we're going to learn how
to adjust the size of our plot
so that we can make our labels fit a bit more easily.
Let's get to it.
What we've got here is our function
that creates a bar chart,
it gets data from the database via app.py.
And that comes from the database through this query.
And essentially, it just plots them using tick label
to give us the x values for the labels,
and here we pass in the height of each column.
However, we had the problem where if we run app.py,
we end up with our pole names here, intersecting each other,
which is not great.
So we decided that in order to make them fit a bit better,
we're going to rotate them
and we're going to discuss how to rotate in the next video,
but in this one, we're going to adjust the size of the plot.
So let's go over to charts.py,
and we're going to add a couple of things.
The first thing is to do fig size in here inside plt.figure,
we can do 10, 10 for example.
This is going to set the figure size
to 10 inches by 10 inches,
where each inch by default is 100 pixels.
So 1000 by 1000 really, if we run this,
now we get a bigger figure.
However, it's not quite big enough,
it would have to be this big in order to avoid our problem.
So although this helps, it's not enough.
Also at this point, I also wanted to add something
that I forgot to add earlier on,
which is a title and the y label for the graph.
This just makes it look a bit nicer,
so feel free to add that in if you want.
Now, we can also adjust the relative sizing
of the elements within a plot.
And so by that I mean exactly this.
I'm gonna run app.py again, and we've got this problem here.
And now if you're using the default plot viewer,
you can click on configure subplots down here.
And that brings up this nice configuration window,
here we can adjust the subplots
and what this means is we can adjust
how far from the left they are
or how much padding they've got on the left,
how far from the bottom they are,
we can also adjust how close to the right they are.
And also how close the top they are.
So these configuration property here
are exactly what we need.
What we want is to adjust the bottom
to give us a little bit more room here,
so that when we rotate our labels,
they will fit in a bit more easily.
Now we're going to learn how to do this in code obviously,
because as soon as you close this
and restart the application, it resets back to the default.
But nonetheless, it's good to visualise
it like this because now when we come
to the code is gonna be a bit easier to understand.
So let me close that and we can go down here
and make our changes.
Under the figure.subplots_adjust and we can pass in
something between zero and one for each value
that's left, top, right and bottom.
Here, we only want to adjust the bottom to 0.35,
seems that is all we need.
If we run app.py now,
you'll see that the plot has a bunch more room underneath.
By the way, I know that we haven't talked
about wspace and hspace.
These are used for when you have multiple plots
in the same figure.
We will come to those later on in this section.
So now that we've got a bit more room,
we can start rotating our labels.
Let's learn how to do that in the next video.
Thank you for watching this one,
I'll see you in the next one.