1
00:00:00,090 --> 00:00:05,460
So a great job, if you made it this far, you have learned a lot about Python and Nampai already.

2
00:00:06,300 --> 00:00:11,700
So the last thing that I want to present to you in this crash course is how you can visualize your data

3
00:00:11,700 --> 00:00:17,610
and your results, because of course, we will also create figures, for example, of our results.

4
00:00:18,780 --> 00:00:24,120
So we call this plotting or creating plots and to do this in Python.

5
00:00:24,390 --> 00:00:28,830
It's very useful to import a library called Months Plot Clip.

6
00:00:30,030 --> 00:00:32,940
So it's basically a mathematical plot library.

7
00:00:33,750 --> 00:00:40,560
And then there's some some option here, which is called PI plot and you write import.

8
00:00:40,860 --> 00:00:43,160
You could read just in parts Matlock lip.

9
00:00:43,200 --> 00:00:48,450
And then every time you want to plot something, you write, plot live dot pi, plot dots and then the

10
00:00:48,450 --> 00:00:49,260
actual command.

11
00:00:49,680 --> 00:00:57,120
And since this is pretty long, we use an abbreviation, so we write import much plot loop PI plot as

12
00:00:57,540 --> 00:00:58,210
Pulte.

13
00:00:58,920 --> 00:01:04,470
So in the following, we only have to write Pulte, which is pretty similar as we did for nonpaying

14
00:01:04,470 --> 00:01:07,710
when we wrote import numpy as NP.

15
00:01:09,330 --> 00:01:16,020
So in most of our files on the following, we will basically run this command in the first cell and

16
00:01:16,020 --> 00:01:17,460
in one of the first lines.

17
00:01:18,030 --> 00:01:23,520
But here, just to make it a bit more or have a better overview of the notebook, I just keep it here.

18
00:01:24,480 --> 00:01:25,200
So we run this.

19
00:01:25,530 --> 00:01:30,570
And now we have loaded the library and we can use it and we can plot nice things.

20
00:01:31,830 --> 00:01:37,470
So the most simple thing you can do is just plot some data points with some coordinates.

21
00:01:38,310 --> 00:01:45,840
So you have some coordinates basically which have an X value and the Y value, and you have several

22
00:01:45,840 --> 00:01:46,290
of these.

23
00:01:47,010 --> 00:01:50,820
So we can just write plot dot scatter.

24
00:01:51,250 --> 00:01:54,300
This is the command for such a list, plot or scatterplot.

25
00:01:54,780 --> 00:02:02,190
And then you provide the two lists, and now it's important you do not provide x one by one.

26
00:02:02,550 --> 00:02:03,630
This is not true.

27
00:02:04,260 --> 00:02:10,800
You provide instead x one x two x three and then you provide a second list with the Y coordinates.

28
00:02:11,550 --> 00:02:16,110
So it's really important to acknowledge here the order of the two things.

29
00:02:16,560 --> 00:02:23,100
So first, all the X coordinates and then all the way coordinates, so we can just do an example here

30
00:02:23,100 --> 00:02:25,950
one, two, three and then maybe four or five.

31
00:02:26,460 --> 00:02:34,260
And for the Y coordinates, we just take some values five one minus one zero two.

32
00:02:36,090 --> 00:02:40,170
So now I made a mistake, so let me check what I did wrong here.

33
00:02:42,330 --> 00:02:44,220
I don't really see it just yet.

34
00:02:45,090 --> 00:02:47,430
It says X and Y must be the same size.

35
00:02:47,430 --> 00:02:49,010
Maybe I did a comma.

36
00:02:49,020 --> 00:02:50,880
Yes, here I made a mistake with the comma.

37
00:02:51,420 --> 00:02:53,760
So maybe it's a good idea that you saw this here.

38
00:02:54,240 --> 00:02:55,860
So just a small mistake here.

39
00:02:56,450 --> 00:03:01,950
I guess this large error message and and most of the cases, it's a good idea to scroll to the bottom

40
00:03:01,950 --> 00:03:05,400
because there it gives you the the error message.

41
00:03:06,360 --> 00:03:09,660
So now they have to stay, have the same size so I can run it.

42
00:03:09,660 --> 00:03:12,270
And you see, we have now our coordinates.

43
00:03:12,870 --> 00:03:19,410
The first point has to coordinate one and five, the second one, two and one and so on.

44
00:03:20,460 --> 00:03:22,920
So this is how you create a scatterplot.

45
00:03:24,690 --> 00:03:28,050
So now this is typically not how we get our data.

46
00:03:28,590 --> 00:03:31,020
So let me show you a bit of a more realistic example.

47
00:03:31,770 --> 00:03:36,030
So let's say, for example, we have some array which we call, I don't know, courts small.

48
00:03:36,690 --> 00:03:38,460
And as I said, it's an array.

49
00:03:39,840 --> 00:03:48,180
And typically at least this is how I program typically or most of the times is I have a first data point,

50
00:03:48,180 --> 00:03:49,770
which has some coordinates.

51
00:03:50,190 --> 00:03:53,970
And let's assume we even have three coordinates X, Y and Z.

52
00:03:54,780 --> 00:03:57,360
So the first point has the coordinates one one one.

53
00:03:57,930 --> 00:04:01,500
Then we have a second point, which has some other coordinates two for eight.

54
00:04:02,370 --> 00:04:07,610
So the next one, you see just a square and cubic numbers.

55
00:04:08,610 --> 00:04:11,430
Of course, I could also generate this list automatically.

56
00:04:11,430 --> 00:04:18,000
But just for the just for the presentation here, let's just write them down.

57
00:04:18,570 --> 00:04:23,340
OK, so now we have five different data points, which all have three coordinates.

58
00:04:24,630 --> 00:04:31,400
So in such a scatterplot which is two dimensional, we can of course only use two of these coordinates.

59
00:04:31,410 --> 00:04:36,480
We can, for example, plots the X and Y coordinates of all of these five points.

60
00:04:37,470 --> 00:04:39,030
So how are we going to do this?

61
00:04:40,230 --> 00:04:45,600
Well, we are, as I said, you really have to be careful here with the syntax because if I would just

62
00:04:45,600 --> 00:04:55,890
right here plot scatter and then quotes one, it would of course give me an error because yeah, the

63
00:04:55,890 --> 00:04:58,230
inputs has a completely wrong shape.

64
00:04:58,920 --> 00:05:04,230
So first, we must shape our data and we do this in the following way.

65
00:05:05,040 --> 00:05:11,520
First of all, he told you that you have to first provide the X coordinates and then the Y coordinates.

66
00:05:12,150 --> 00:05:16,110
So what we're going to do is we are going to transpose the array.

67
00:05:16,980 --> 00:05:25,260
So this basically just means reorder the array and now the first cell or the first brackets will contain

68
00:05:25,260 --> 00:05:25,990
this value.

69
00:05:26,060 --> 00:05:28,220
This this is this.

70
00:05:28,470 --> 00:05:34,680
So basically all the X coordinates and you do this by writing down quotes one dot capital t.

71
00:05:35,880 --> 00:05:42,110
So this Ensino has reordered this array.

72
00:05:42,120 --> 00:05:43,350
So we started from here.

73
00:05:43,380 --> 00:05:51,960
Now we are here and now what we can do is we can assign this array and individually these three rows

74
00:05:51,960 --> 00:05:54,720
here, we can assign them to new variables.

75
00:05:55,320 --> 00:05:59,100
So I call them X1 y one z one.

76
00:06:02,190 --> 00:06:08,940
And now, if I called them just to show you next, one will just be this line here.

77
00:06:10,830 --> 00:06:13,560
Why one will be the second line and so on.

78
00:06:14,580 --> 00:06:20,700
And so this is not really nice, I think, because what we can do next is we are basically we don't

79
00:06:20,700 --> 00:06:24,500
have to do anything anymore because we already have now the correct shape.

80
00:06:24,510 --> 00:06:26,760
We can just use them.

81
00:06:27,450 --> 00:06:38,100
So what we can do now is we can write, plot, scatter and just write x one comma y one.

82
00:06:38,280 --> 00:06:43,530
And that's basically all we have to do, because now you see, this has the same syntax as this one

83
00:06:43,530 --> 00:06:43,800
here.

84
00:06:44,520 --> 00:06:49,110
So I can just run it and you see we get now the plot.

85
00:06:49,770 --> 00:06:54,390
So on the x axis, we have this line here and on the y axis we have this one.

86
00:06:55,320 --> 00:06:59,160
So the values are one, four, nine, 16 and twenty five.

87
00:07:00,480 --> 00:07:04,590
So what's also nice is we can just plot in the same plot.

88
00:07:05,370 --> 00:07:06,540
The Z components as well.

89
00:07:08,490 --> 00:07:13,860
So now we have plotted the X components on the x axis and the Z component at the y axis.

90
00:07:14,430 --> 00:07:15,790
So you see, they are different No.

91
00:07:15,810 --> 00:07:20,010
One, eight, 27, 64 125.

92
00:07:21,600 --> 00:07:28,530
So maybe to just make this a bit clearer and to understand it a bit better, we should add labels to

93
00:07:28,530 --> 00:07:31,620
our plots and we can do this by writing before we do this here.

94
00:07:32,760 --> 00:07:34,260
Plot X label.

95
00:07:36,970 --> 00:07:48,640
X so now we have the X on the x axis, and to make the Y label, we write Peltier Dot Y label.

96
00:07:49,810 --> 00:07:55,420
And here we I would say we just write y commas because we plot both of them.

97
00:07:55,840 --> 00:08:00,190
The Y coordinate is blue and the Z coordinate is orange.

98
00:08:01,500 --> 00:08:07,980
OK, so now we have a nice scatterplot, and I'll show you how you can handle such data points that

99
00:08:07,980 --> 00:08:10,080
we will typically get from our calculations.

100
00:08:11,460 --> 00:08:13,860
Now, of course, there are not only these scatter plots.

101
00:08:14,340 --> 00:08:19,470
You also want to plot conventional functions and you want to connect them with a line.

102
00:08:20,280 --> 00:08:26,370
And the truth is, most of the times you do not straightforwardly plot a function as a line.

103
00:08:26,610 --> 00:08:33,179
Instead, what you do, you generate some data points which are very dense, you could say, and then

104
00:08:33,179 --> 00:08:37,140
you connect these with lines and so you emulate the real function.

105
00:08:38,460 --> 00:08:40,710
So let me show you what I mean by this.

106
00:08:41,700 --> 00:08:48,190
So what we're going to do here is we are going to first generate some data points.

107
00:08:48,780 --> 00:08:50,850
So I just write your data points.

108
00:08:51,780 --> 00:08:57,750
And then what we're going to do is we first are going to generate some X coordinates.

109
00:08:58,830 --> 00:09:07,430
And for this, we should do something like zero one two three four five like we did here.

110
00:09:07,440 --> 00:09:09,510
So this would be our data points.

111
00:09:10,110 --> 00:09:15,360
However, since we want to have a smooth function, we must make them very, very dense.

112
00:09:15,420 --> 00:09:19,770
So we should do instead something like zero, 0.1 0.2.

113
00:09:20,010 --> 00:09:20,490
And so.

114
00:09:21,540 --> 00:09:26,640
So this is, of course, very, very tedious, and you need many of these points to generate a smooth

115
00:09:26,640 --> 00:09:27,180
function.

116
00:09:28,110 --> 00:09:35,820
So to generate such a list, what you can do is you can just write and p dot little space and then you

117
00:09:35,820 --> 00:09:43,590
provide starting value, then the end value and the number of points between these two values.

118
00:09:44,430 --> 00:09:50,550
So you could, for example, write one hundred and now I can show you what this looks like.

119
00:09:51,720 --> 00:09:56,670
This is an array with 100 data points between zero and four.

120
00:09:57,900 --> 00:10:06,300
So it's often better to add you add additional data points because then we will have such nice numbers

121
00:10:06,300 --> 00:10:06,540
here.

122
00:10:06,810 --> 00:10:10,290
This is because the first and the last data point to count as well.

123
00:10:10,620 --> 00:10:15,690
So when we write here 101, we actually have a distance here of zero point zero four.

124
00:10:16,410 --> 00:10:19,290
But it wouldn't be a problem to write 100 here.

125
00:10:20,610 --> 00:10:27,090
OK, so now we have this list, and what we're going to do next is we are going to generate a loyalists

126
00:10:27,340 --> 00:10:28,440
our actual values.

127
00:10:29,790 --> 00:10:37,980
So let's say we want to plot the function just a random function one plus two times cosine, which would

128
00:10:37,980 --> 00:10:39,300
be an PIMCO's.

129
00:10:40,290 --> 00:10:46,890
And then I would just say three X. So this would be our function that we're going to plots.

130
00:10:47,310 --> 00:10:50,710
And of course, the Y values must also be a list.

131
00:10:51,000 --> 00:10:56,550
So the X values must also be a list, and we just take our list that we have just generated.

132
00:10:57,600 --> 00:10:58,560
So I run this.

133
00:10:58,560 --> 00:11:05,340
And now you see the Y values are both also a list or array betters, say, and we can plot.

134
00:11:05,370 --> 00:11:13,020
Now both of these lists together, as we did before, so we can, of course, now just load this one

135
00:11:13,020 --> 00:11:13,260
here.

136
00:11:14,880 --> 00:11:15,900
The scatterplot?

137
00:11:19,210 --> 00:11:26,350
And this will be the function, and if you now want to connect these very dense points, you can write.

138
00:11:27,450 --> 00:11:31,740
Plots are Pulte Dot plots.

139
00:11:31,830 --> 00:11:32,940
This is the correct comment.

140
00:11:33,930 --> 00:11:36,930
And now you see it gets a rather smooth line here.

141
00:11:37,800 --> 00:11:45,780
But for example, if I would decrease the number of data points to 21, then you would see these are

142
00:11:45,780 --> 00:11:50,250
really just lines connecting the data points, which make a not so smooth function.

143
00:11:51,240 --> 00:11:55,260
And of course, the higher the number goes, the smoother the function will look.

144
00:11:56,430 --> 00:11:59,380
So I see I would say 101 was just fine.

145
00:12:00,030 --> 00:12:03,240
And yeah, we can definitely work with this.

146
00:12:04,560 --> 00:12:06,510
So what else can we do here?

147
00:12:06,840 --> 00:12:12,000
Well, we can, for example, specify again the labels which we have done previously.

148
00:12:12,010 --> 00:12:13,350
But I want to show you something new.

149
00:12:13,350 --> 00:12:16,860
I want to show you the limits on the XS.

150
00:12:17,190 --> 00:12:18,930
For example, the x axis.

151
00:12:19,770 --> 00:12:28,050
And so the syntax here is x limb than normal brackets and in the cupboard or in the yeah, in the in

152
00:12:28,050 --> 00:12:32,490
these brackets, we write zero comma eight, for example.

153
00:12:33,300 --> 00:12:37,770
And so we have now changed the X range from zero to eight.

154
00:12:39,090 --> 00:12:47,760
And what I'm going to do next is I'm going to add some more data points and I want to plot.

155
00:12:48,690 --> 00:12:52,740
So let's say I want to create more data.

156
00:12:52,740 --> 00:12:59,730
So I just copy this one here and say X to Y to X two.

157
00:12:59,730 --> 00:13:07,410
And this time I want to plot the values of four x between four and eight to fill the remaining space

158
00:13:07,410 --> 00:13:07,650
here.

159
00:13:08,340 --> 00:13:14,340
So I write for Comma eight and I want to just continue with the same function.

160
00:13:15,840 --> 00:13:18,780
So now I will add another plot here.

161
00:13:18,780 --> 00:13:24,900
I will add the plots of X two and Y two.

162
00:13:25,950 --> 00:13:30,010
And of course, if I do it like this, you see, we have now merged these two plots.

163
00:13:30,960 --> 00:13:33,290
But you can also merge different types of plots.

164
00:13:33,300 --> 00:13:36,290
For example, you could write plot dot scatter.

165
00:13:37,150 --> 00:13:39,090
And now you would get such a graph.

166
00:13:40,880 --> 00:13:47,600
All right, so you see, it's really nice to are really easy to plot stuff, you just have to remember

167
00:13:47,780 --> 00:13:54,050
that you cannot just provide a function that you plot, but instead you must always generate lists or

168
00:13:54,050 --> 00:13:55,880
arrays that you then plot.

169
00:13:56,450 --> 00:14:00,260
So you have really the full control over the way you plot things.

170
00:14:01,730 --> 00:14:07,820
So the very last thing that I want to show you is that you can also export figures and save them, and

171
00:14:07,820 --> 00:14:08,630
this is pretty easy.

172
00:14:09,120 --> 00:14:13,460
Interest rate potti dot safe, fake for, say, figure.

173
00:14:13,970 --> 00:14:18,860
And then you just have to provide a name to write, test plot dot.

174
00:14:19,040 --> 00:14:22,940
And then, you know, you could, for example, use a page file.

175
00:14:23,460 --> 00:14:28,010
You run this and it gives you the output because we are in Jupyter notebook.

176
00:14:28,340 --> 00:14:35,900
If you would be in a Python notebook, it would not give you the output here, but you would then export

177
00:14:35,900 --> 00:14:42,110
the file and you can look it up in your directory where this notebook here is located.

178
00:14:43,130 --> 00:14:46,970
And you see, I have opened here the image that we have just exported.

