-: Hi guys and welcome back.
In this video, we're going to learn
how to export one figure with multiple sets
of axes inside it.
There's nothing magical about it.
As you can see, the code is pretty short
but let's get to it.
Here we've got a figure.
Inside of it, we've got two subplots
that are in two columns and these are the IDs one and two,
and then each one of them,
we're plotting a line chart.
Nothing too fancy here.
I just wanted to show you how you can do this.
At the end, we're doing savefig as before
and all that's gonna happen when we run this
is we're gonna create our image
and it has the two elements here.
Remember that if we do plt.show instead,
so we'll do plt.show here, and we run this,
we've got our configuration
and here we can adjust the spacing between plots like that.
So the width space or wspace goes from zero to one.
Zero means there are completely joined together.
One means that the space between two graphs
is equal to the average width of an x-axis.
So here you can see this, this and this
are all the ame width.
.5 though means that the width between two graphs
is equal to 1/2 of the average width of an x-axis.
And so it is pretty handy to separate graphs more
or less appropriately.
Hspace is the same but of course,
it separates in rows rather than columns
and we only have one row here,
so it doesn't take effect.
However, this can be handy when you want
to produce an image.
You can adjust the spacing between plots for better export.
So let's try to do that without plt.show.
I'll bring back figure.savefig
and now we can do here figure.subplots_adjust wspace
equals 0.5 let's say.
We can run this
and what we get now is that the graphs
are a bit more separated.
Not that we've got some pretty larger borders
around the graphs
and we can get rid of them using
the tight bounding box method.
So we can do bbox_inches equal tight
and that is going to get rid of some of those borders
so we can open this again
and now they're a bit closer to the edge.
Do note, of course, if you add the titles
or axis labels and stuff like that,
there will still be room for those as well if you need them.
So just to recap, the savefig call changes the size
of the figure.
You can set it to constrain the plot inside it
with bbox_inches equal tight
and you can also add padding if you want.
This subplots_ adjust method here changes each
of the plot's settings
and here we've used it to distribute the plot horizontally
a bit better.
But the other settings in here also take effect
as we've seen in this video and in the last.
Thank you, guys for joining me in this video.
I hope you've learned something
and I'll see you in the next one.