1
00:00:00,760 --> 00:00:01,660
Hello, dear friend.

2
00:00:01,690 --> 00:00:08,170
So in this lesson, we are going to learn how to customize our figure in matplotlib library.

3
00:00:08,470 --> 00:00:10,600
So let's get started.

4
00:00:12,570 --> 00:00:18,630
So I'm sure you remember we have talked about the figure object in our last lesson, we use figures

5
00:00:18,630 --> 00:00:23,610
that are simple, and I say there will talk about it in greater depth later.

6
00:00:23,940 --> 00:00:27,330
Hey, hey, now, later, so we can.

7
00:00:29,040 --> 00:00:35,430
What I'm going to do is lay out some pretty complex examples so that we can understand this better.

8
00:00:36,150 --> 00:00:37,890
And if you're ready, we can start.

9
00:00:39,120 --> 00:00:40,890
And as always, we will need to import.

10
00:00:40,890 --> 00:00:43,770
Our library's first important number is N.P..

11
00:00:47,650 --> 00:00:51,760
Import matplotlib, that pipeline as PLG.

12
00:00:55,380 --> 00:00:59,940
And, of course, we'll need to enter a magic statement for displaying our plot outputs inside the Jupiter

13
00:00:59,940 --> 00:01:00,870
notebook itself.

14
00:01:01,850 --> 00:01:02,660
Percent.

15
00:01:03,570 --> 00:01:04,530
Matplotlib.

16
00:01:06,370 --> 00:01:06,970
Inline.

17
00:01:08,210 --> 00:01:15,440
So now we can create an incendiary object between one and nine using the arrange function from the numbI

18
00:01:15,440 --> 00:01:16,040
library.

19
00:01:17,480 --> 00:01:21,350
X equals and P on a range one nine.

20
00:01:24,310 --> 00:01:29,140
Our variables serve as values on the X axis of the graph.

21
00:01:29,560 --> 00:01:31,990
So now we need another variable for the Y axis.

22
00:01:32,000 --> 00:01:35,590
So let's define that Y equals np dot arrange.

23
00:01:37,090 --> 00:01:38,980
Three, 27, three.

24
00:01:41,670 --> 00:01:42,730
So that seems OK.

25
00:01:42,750 --> 00:01:43,920
Our variables are ready.

26
00:01:44,370 --> 00:01:52,710
So let's move on here, will need to define one figure and four axes, figure axes.

27
00:01:54,690 --> 00:01:57,060
Equals plot, not subplots.

28
00:01:58,520 --> 00:02:03,920
Now, if we don't specify any parameter here, we're going to get an axis with one column in one row.

29
00:02:04,790 --> 00:02:06,730
But we're going to need four axes.

30
00:02:06,740 --> 00:02:07,910
So let's specify that.

31
00:02:08,380 --> 00:02:13,880
And rows equals two and calls equals two.

32
00:02:14,750 --> 00:02:20,420
So now when we run this code, the figure will equal our figure variable and the axes will equal our

33
00:02:20,420 --> 00:02:21,560
axes variable.

34
00:02:21,590 --> 00:02:21,890
Right.

35
00:02:22,880 --> 00:02:23,150
All right.

36
00:02:23,150 --> 00:02:25,310
So let's run it and check the result.

37
00:02:27,340 --> 00:02:28,150
So we get this.

38
00:02:28,450 --> 00:02:29,020
What do you know?

39
00:02:29,710 --> 00:02:33,820
We get our four axes, but I see a little problem here to you.

40
00:02:35,500 --> 00:02:41,380
Can you see that these axes are a little close to each other and it's a little messy?

41
00:02:42,070 --> 00:02:48,760
So with the help of this function, we can get a more well readable result.

42
00:02:48,790 --> 00:02:49,060
Yeah.

43
00:02:49,570 --> 00:02:50,380
So let's check it out.

44
00:02:51,390 --> 00:02:53,640
Plot, tight layout.

45
00:03:01,140 --> 00:03:03,480
So let's continue with two axes for now.

46
00:03:03,510 --> 00:03:06,960
For example, we have two rows, one column.

47
00:03:07,410 --> 00:03:11,790
So if we change the end, calls value to one.

48
00:03:13,650 --> 00:03:14,820
Yeah, we're going to get this.

49
00:03:16,500 --> 00:03:22,440
Now, if you want, we can see our axes, variable type print type axes.

50
00:03:27,560 --> 00:03:29,960
So here are axes is a number of Uray.

51
00:03:31,150 --> 00:03:37,330
Or we can print the first or second axes on the screen, Brent axes zero.

52
00:03:41,560 --> 00:03:43,420
Brent axes one.

53
00:03:45,670 --> 00:03:50,140
Now you know something, we can also iterate the axes with for loop.

54
00:03:51,210 --> 00:03:53,190
For acts and axes.

55
00:03:56,870 --> 00:03:58,010
Exact plot.

56
00:04:00,430 --> 00:04:01,180
X y.

57
00:04:03,910 --> 00:04:04,240
Print.

58
00:04:06,100 --> 00:04:09,060
So when we've run this code, we iterate our axes.

59
00:04:09,130 --> 00:04:13,180
Also, we plot a plot in every axes.

60
00:04:14,400 --> 00:04:14,820
Let's see.

61
00:04:16,300 --> 00:04:16,710
Cool.

62
00:04:17,380 --> 00:04:20,770
So we can also plot a different plot in every axes.

63
00:04:32,410 --> 00:04:33,490
Actually, zero.

64
00:04:34,850 --> 00:04:43,520
Dot plot X Y axes, one dot plot X X two.

65
00:04:45,810 --> 00:04:46,860
And there's a result.

66
00:04:48,540 --> 00:04:55,560
And of course, we could give a title to each of them, and I guess you already remember how to do it

67
00:04:55,560 --> 00:05:00,960
from our previous lesson axes zero dot set title.

68
00:05:05,020 --> 00:05:06,040
X y Graaf.

69
00:05:10,170 --> 00:05:13,050
Axes, one dot set title.

70
00:05:16,210 --> 00:05:17,800
X Square graph.

71
00:05:20,880 --> 00:05:22,080
And here's that result.

72
00:05:27,600 --> 00:05:34,760
All righty then, so we have created our figures, but maybe sometimes we will need different size of

73
00:05:34,780 --> 00:05:36,910
figures like bigger or smaller maybe.

74
00:05:37,540 --> 00:05:44,470
So for this, our beautiful matplotlib is figure function provides us a parameter called figure size.

75
00:05:45,410 --> 00:05:46,630
You'll see how that works.

76
00:05:46,990 --> 00:05:47,650
I'll show you.

77
00:05:48,520 --> 00:05:54,730
So first will define a new variable named a figure as figure s equals plot dot figure.

78
00:05:56,320 --> 00:06:02,800
So now we can add a parameter here, but before we do that, we should also create an axes and see it

79
00:06:02,800 --> 00:06:07,540
more clearly axes as equals figure as.

80
00:06:09,540 --> 00:06:11,190
Don't add axes.

81
00:06:14,230 --> 00:06:17,080
So here we specify the starting point.

82
00:06:19,560 --> 00:06:22,470
Zero zero and Covid all.

83
00:06:22,590 --> 00:06:23,520
One one.

84
00:06:24,890 --> 00:06:30,800
And then, as you know, when we use the ad axes, we give a value from zero to one.

85
00:06:31,130 --> 00:06:35,720
And if we choose one, then our axes will cover completely the figure.

86
00:06:37,010 --> 00:06:37,280
All right.

87
00:06:37,280 --> 00:06:41,030
So it seems our axes are ready, so let's start to plot it out.

88
00:06:42,500 --> 00:06:43,760
Axes escort.

89
00:06:45,130 --> 00:06:45,580
Plant.

90
00:06:46,680 --> 00:06:50,100
X y 025.

91
00:06:51,230 --> 00:06:55,280
And give it a different color if you want to, color equals orange.

92
00:06:58,250 --> 00:06:59,870
Now our figure and axes are ready.

93
00:07:00,050 --> 00:07:01,970
And here's what it looks like.

94
00:07:03,420 --> 00:07:06,420
So now let's employ our parameter.

95
00:07:07,720 --> 00:07:09,190
Fig size equals.

96
00:07:10,290 --> 00:07:13,890
And size values will put it six and four.

97
00:07:14,310 --> 00:07:15,120
So let's run that.

98
00:07:20,010 --> 00:07:22,550
And there's a result we get a bigger graph.

99
00:07:23,620 --> 00:07:31,420
So I hope your guest hears the first value, it's equal access and the second value is equal to the

100
00:07:31,420 --> 00:07:32,650
Y axis.

101
00:07:33,790 --> 00:07:38,110
So let's change the values three to four and run it again.

102
00:07:40,730 --> 00:07:41,540
There's that resow.

103
00:07:43,140 --> 00:07:47,730
And also, if we want to, we can change the background color of our graph or this, we can use the

104
00:07:47,730 --> 00:07:48,960
face color parameter.

105
00:07:49,470 --> 00:07:50,160
Let's try it out.

106
00:07:51,790 --> 00:07:52,780
Face colour equals.

107
00:07:55,670 --> 00:07:56,240
Red.

108
00:07:59,680 --> 00:08:00,970
And the result is here.

109
00:08:02,610 --> 00:08:10,080
All right, so let's move on with this, define another figure and axes, variable figure two axes,

110
00:08:10,080 --> 00:08:11,220
two equals.

111
00:08:13,720 --> 00:08:22,120
Plot that subplot this time, let's define one row and two columns and rows equals one.

112
00:08:23,750 --> 00:08:25,400
And calls equals two.

113
00:08:26,000 --> 00:08:32,730
And the figure size will there be 14 and six figure size equals 14.

114
00:08:32,750 --> 00:08:33,200
Six.

115
00:08:39,530 --> 00:08:44,690
Now our axes are ready, so let's plot our figures in axes to.

116
00:08:46,400 --> 00:08:47,630
Zero dot plot.

117
00:08:48,670 --> 00:08:52,540
This time, we can use our WI variable and its third power.

118
00:08:52,900 --> 00:08:56,380
So why, why three?

119
00:08:57,160 --> 00:09:01,330
And the color let it be orange color equals orange.

120
00:09:02,780 --> 00:09:06,050
So specify the axes, title axes to.

121
00:09:07,530 --> 00:09:09,030
Zero set title.

122
00:09:10,170 --> 00:09:11,160
So the title is.

123
00:09:12,380 --> 00:09:13,160
Why graph?

124
00:09:16,570 --> 00:09:18,220
All right, so the first one is done.

125
00:09:18,680 --> 00:09:21,580
Now let's get to the second one axes to.

126
00:09:22,520 --> 00:09:34,580
One dot plot, this time we'll use our X variable and it's zero dot three power X X zero to three and

127
00:09:34,580 --> 00:09:39,020
the color let it be Purple Color equals purple.

128
00:09:42,560 --> 00:09:48,590
So now let's specify the axes, tidal axes to one that set tidal.

129
00:09:49,490 --> 00:09:51,680
And title is X graph.

130
00:09:53,560 --> 00:09:55,240
It's now our figure and axes are ready.

131
00:09:57,730 --> 00:09:58,570
Let's run it.

132
00:10:00,050 --> 00:10:01,730
And here's the result.

133
00:10:03,670 --> 00:10:08,620
So now let's try to say this figure to a PDF or a PNGDF file.

134
00:10:09,400 --> 00:10:12,310
So first, let's check out our figure again for you to.

135
00:10:15,560 --> 00:10:19,490
And now we can save our figure with the help of the save figure function.

136
00:10:20,150 --> 00:10:25,460
So let's use it figure to dot C fig.

137
00:10:30,900 --> 00:10:33,300
Figure to Duckpin G.

138
00:10:37,340 --> 00:10:40,490
And we have success, we saved our figure, so let's check it out.

139
00:10:41,550 --> 00:10:46,050
And you can see here that it placed it in the same directory as our Jupiter files.

140
00:10:48,390 --> 00:10:55,020
So also, we can save that as a PDF file, the same way for you to DOT.

141
00:10:57,260 --> 00:10:58,190
Save Fig.

142
00:11:01,150 --> 00:11:02,350
Figure to that.

143
00:11:03,450 --> 00:11:04,710
PD f.

144
00:11:08,420 --> 00:11:08,870
And.

145
00:11:09,870 --> 00:11:11,310
There's our PDF file.

146
00:11:12,690 --> 00:11:14,820
Well, you know, we can we can make one more thing.

147
00:11:15,150 --> 00:11:20,490
So do you remember way back, if you can, the legend parameter from our previous lesson?

148
00:11:21,210 --> 00:11:26,250
So with the help of this parameter, we can add a legend here, too, so let's try it.

149
00:11:27,450 --> 00:11:29,970
So to find a different figure and axes again.

150
00:11:30,810 --> 00:11:32,010
Figure three.

151
00:11:34,530 --> 00:11:35,760
Axes three.

152
00:11:37,760 --> 00:11:45,140
Equals plot dot subplots and figure size, let it be 14 and six.

153
00:11:48,080 --> 00:11:56,150
So our figure will be fully covered by these axes, so we'll need to specify it axes three equals.

154
00:11:57,340 --> 00:11:58,510
Figure three Dot.

155
00:12:00,080 --> 00:12:01,460
Ad axes.

156
00:12:05,110 --> 00:12:07,810
Zero zero one one.

157
00:12:09,420 --> 00:12:11,700
So let's draw four different plots.

158
00:12:12,000 --> 00:12:17,040
First plot is why and it's square root axes, three to.

159
00:12:18,490 --> 00:12:19,030
Plot.

160
00:12:20,760 --> 00:12:21,200
Why?

161
00:12:21,330 --> 00:12:21,900
Why?

162
00:12:23,380 --> 00:12:24,580
Zero, not five.

163
00:12:26,170 --> 00:12:27,880
Specify its label as.

164
00:12:29,520 --> 00:12:30,780
Why square root?

165
00:12:34,290 --> 00:12:35,790
And the color is orange.

166
00:12:38,810 --> 00:12:42,110
Second plot is X and its second power.

167
00:12:43,120 --> 00:12:44,740
Axes, three dot plot.

168
00:12:47,220 --> 00:12:49,470
X x two.

169
00:12:50,430 --> 00:12:54,390
And we'll specify its label as X second power.

170
00:12:58,720 --> 00:12:59,830
And the colors purple.

171
00:13:04,570 --> 00:13:09,400
Third plot plodders X and Y, axes, three dot plot.

172
00:13:10,990 --> 00:13:12,040
X y.

173
00:13:13,810 --> 00:13:16,570
And we'll specify its label to be x y.

174
00:13:21,900 --> 00:13:23,310
And the color will be blue.

175
00:13:26,290 --> 00:13:32,170
Last plodders, why and wise signed value so axes three dot plot.

176
00:13:34,440 --> 00:13:36,180
Why airport sign?

177
00:13:39,630 --> 00:13:43,470
And specify its label to be why why sign?

178
00:13:49,190 --> 00:13:50,570
So that color is going to be red.

179
00:13:54,620 --> 00:13:56,720
So we can finally add in our legend here.

180
00:14:00,740 --> 00:14:01,820
And run the code.

181
00:14:05,000 --> 00:14:06,110
And here's the result.

182
00:14:07,310 --> 00:14:13,610
It's our figure and our axes, plots are here and all the glorious detail here is our legend.

183
00:14:14,890 --> 00:14:17,650
We defined a figure and an axis.

184
00:14:18,160 --> 00:14:20,200
We plotted four different plots.

185
00:14:20,680 --> 00:14:22,120
And we even added a legend.

186
00:14:24,850 --> 00:14:25,510
So that's it.

187
00:14:25,540 --> 00:14:27,550
This is pretty comprehensive.

188
00:14:28,390 --> 00:14:33,310
And we have covered how to customize a figure in matplotlib.

189
00:14:33,910 --> 00:14:39,640
So in the next lesson, what we're going to do is learn how to customize a graphic in matplotlib.

190
00:14:40,360 --> 00:14:41,590
So that's going to be a lot of fun.

191
00:14:41,590 --> 00:14:43,750
And I will see you in the next lesson.

192
00:14:43,810 --> 00:14:45,040
I can count on it.

193
00:14:45,490 --> 00:14:46,840
Until then, have a nice day.
