WEBVTT

1
00:00:00.000 --> 00:00:01.540
<v ->Hi guys and welcome back.</v>

2
00:00:01.540 --> 00:00:02.760
In this video, we're going to learn

3
00:00:02.760 --> 00:00:05.750
how to export one figure with multiple sets

4
00:00:05.750 --> 00:00:07.710
of axes inside it.

5
00:00:07.710 --> 00:00:09.030
There's nothing magical about it.

6
00:00:09.030 --> 00:00:11.060
As you can see, the code is pretty short

7
00:00:11.060 --> 00:00:12.690
but let's get to it.

8
00:00:12.690 --> 00:00:14.530
Here we've got a figure.

9
00:00:14.530 --> 00:00:16.590
Inside of it, we've got two subplots

10
00:00:16.590 --> 00:00:21.590
that are in two columns and these are the IDs one and two,

11
00:00:21.620 --> 00:00:22.700
and then each one of them,

12
00:00:22.700 --> 00:00:24.100
we're plotting a line chart.

13
00:00:24.100 --> 00:00:25.490
Nothing too fancy here.

14
00:00:25.490 --> 00:00:27.580
I just wanted to show you how you can do this.

15
00:00:27.580 --> 00:00:30.060
At the end, we're doing savefig as before

16
00:00:30.060 --> 00:00:32.110
and all that's gonna happen when we run this

17
00:00:32.110 --> 00:00:33.840
is we're gonna create our image

18
00:00:33.840 --> 00:00:37.140
and it has the two elements here.

19
00:00:37.140 --> 00:00:40.540
Remember that if we do plt.show instead,

20
00:00:40.540 --> 00:00:43.183
so we'll do plt.show here, and we run this,

21
00:00:44.200 --> 00:00:45.810
we've got our configuration

22
00:00:45.810 --> 00:00:50.510
and here we can adjust the spacing between plots like that.

23
00:00:50.510 --> 00:00:55.000
So the width space or wspace goes from zero to one.

24
00:00:55.000 --> 00:00:57.270
Zero means there are completely joined together.

25
00:00:57.270 --> 00:01:01.700
One means that the space between two graphs

26
00:01:01.700 --> 00:01:05.340
is equal to the average width of an x-axis.

27
00:01:05.340 --> 00:01:08.580
So here you can see this, this and this

28
00:01:08.580 --> 00:01:09.917
are all the ame width.

29
00:01:09.917 --> 00:01:12.580
.5 though means that the width between two graphs

30
00:01:12.580 --> 00:01:16.090
is equal to 1/2 of the average width of an x-axis.

31
00:01:16.090 --> 00:01:18.960
And so it is pretty handy to separate graphs more

32
00:01:18.960 --> 00:01:21.080
or less appropriately.

33
00:01:21.080 --> 00:01:22.670
Hspace is the same but of course,

34
00:01:22.670 --> 00:01:25.010
it separates in rows rather than columns

35
00:01:25.010 --> 00:01:26.270
and we only have one row here,

36
00:01:26.270 --> 00:01:28.110
so it doesn't take effect.

37
00:01:28.110 --> 00:01:30.490
However, this can be handy when you want

38
00:01:30.490 --> 00:01:31.690
to produce an image.

39
00:01:31.690 --> 00:01:36.240
You can adjust the spacing between plots for better export.

40
00:01:36.240 --> 00:01:38.180
So let's try to do that without plt.show.

41
00:01:38.180 --> 00:01:39.806
I'll bring back figure.savefig

42
00:01:39.806 --> 00:01:42.087
and now we can do here figure.subplots_adjust wspace

43
00:01:43.870 --> 00:01:45.710
equals 0.5 let's say.

44
00:01:45.710 --> 00:01:47.150
We can run this

45
00:01:47.150 --> 00:01:48.850
and what we get now is that the graphs

46
00:01:48.850 --> 00:01:50.183
are a bit more separated.

47
00:01:51.060 --> 00:01:53.170
Not that we've got some pretty larger borders

48
00:01:53.170 --> 00:01:54.350
around the graphs

49
00:01:54.350 --> 00:01:55.830
and we can get rid of them using

50
00:01:55.830 --> 00:01:57.520
the tight bounding box method.

51
00:01:57.520 --> 00:02:01.110
So we can do bbox_inches equal tight

52
00:02:01.110 --> 00:02:03.770
and that is going to get rid of some of those borders

53
00:02:03.770 --> 00:02:05.110
so we can open this again

54
00:02:05.110 --> 00:02:06.900
and now they're a bit closer to the edge.

55
00:02:06.900 --> 00:02:09.130
Do note, of course, if you add the titles

56
00:02:09.130 --> 00:02:10.940
or axis labels and stuff like that,

57
00:02:10.940 --> 00:02:13.870
there will still be room for those as well if you need them.

58
00:02:13.870 --> 00:02:17.500
So just to recap, the savefig call changes the size

59
00:02:17.500 --> 00:02:18.333
of the figure.

60
00:02:18.333 --> 00:02:20.450
You can set it to constrain the plot inside it

61
00:02:20.450 --> 00:02:23.000
with bbox_inches equal tight

62
00:02:23.000 --> 00:02:25.470
and you can also add padding if you want.

63
00:02:25.470 --> 00:02:28.970
This subplots_ adjust method here changes each

64
00:02:28.970 --> 00:02:30.320
of the plot's settings

65
00:02:30.320 --> 00:02:33.840
and here we've used it to distribute the plot horizontally

66
00:02:33.840 --> 00:02:35.060
a bit better.

67
00:02:35.060 --> 00:02:37.990
But the other settings in here also take effect

68
00:02:37.990 --> 00:02:40.448
as we've seen in this video and in the last.

69
00:02:40.448 --> 00:02:42.280
Thank you, guys for joining me in this video.

70
00:02:42.280 --> 00:02:43.520
I hope you've learned something

71
00:02:43.520 --> 00:02:45.170
and I'll see you in the next one.

