Data Visualization With Matplotlib 3.x and Python | Dr. Gary White | Skillshare

Playback Speed


  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x

Data Visualization With Matplotlib 3.x and Python

teacher avatar Dr. Gary White, Senior Data Scientist

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Lessons in This Class

57 Lessons (4h)
    • 1. Introducing Matplotlib

      1:52
    • 2. Installing Matplotlib

      3:50
    • 3. Introduction

      3:01
    • 4. Multiple Lines

      2:27
    • 5. Line Colours

      4:38
    • 6. Line Styles

      2:45
    • 7. Axis Limits

      3:09
    • 8. Saving Figures

      5:00
    • 9. Matlab Style

      4:03
    • 10. Object Oriented Style

      5:05
    • 11. Twin Axis

      5:55
    • 12. Gridspec

      5:42
    • 13. Adjustable Axis

      1:54
    • 14. Axis Zoom

      2:39
    • 15. Scatter Plot

      2:44
    • 16. Scatter Markers

      1:42
    • 17. plt.scatter

      7:13
    • 18. Density Plots

      8:15
    • 19. Histograms

      7:18
    • 20. 2D Histrograms

      5:07
    • 21. Kernal Density Estimation

      2:11
    • 22. Barchart

      5:01
    • 23. Multiple Barcharts

      3:34
    • 24. Stacked Barcharts

      2:19
    • 25. Boxplot

      3:59
    • 26. Piechart

      6:34
    • 27. Anatomy of a Figure

      4:28
    • 28. Plot Axis

      2:15
    • 29. Plot Legend

      4:38
    • 30. Multiple Legends

      2:34
    • 31. Nonlinear Axis

      3:12
    • 32. Stylesheets

      3:51
    • 33. Text

      5:27
    • 34. Arrows and Annotation

      6:42
    • 35. LaTex

      3:15
    • 36. Shapes

      5:54
    • 37. Matplotlib Unchained

      2:13
    • 38. Basic Errorbars

      4:53
    • 39. Continuous Error

      5:23
    • 40. Hexbin

      10:22
    • 41. Colours

      2:04
    • 42. Les Mis

      3:34
    • 43. 3D Points and Lines

      5:39
    • 44. 3D Contour Plots

      4:00
    • 45. 3D Surface Plots

      3:21
    • 46. Tube Stations

      3:10
    • 47. Nightshade

      3:25
    • 48. Global Map

      2:04
    • 49. Plotting Images

      5:58
    • 50. Blurring Images

      2:55
    • 51. Circle Clip

      5:09
    • 52. Ancombe's Quadrant

      5:53
    • 53. Scatter Plot

      7:11
    • 54. Scatter Plot Matrix

      2:34
    • 55. Violen Plot

      4:36
    • 56. Kernal Density Estimation

      1:50
    • 57. Annotated Heatmap

      4:25
  • --
  • Beginner level
  • Intermediate level
  • Advanced level
  • All levels
  • Beg/Int level
  • Int/Adv level

Community Generated

The level is determined by a majority opinion of students who have reviewed this class. The teacher's recommendation is shown until at least 5 student responses are collected.

43

Students

--

Projects

About This Class

This course is about creating graphs using Matplotlib and Python. With over 50 lectures we take a deep dive into the Matplotlib API and show you how to create impressive figures. We go through a number of different visualisations: barplots, scatter plots, histograms, pie charts and learning how to customise them all as well. This course will teach you everything that you need to know to get started creating impressive visualizations in Python. We will also look at some additional libraries such as Seaborn, Bokeh and Cartopy that can be used to create impressive interactive and geographical data plots.

The course has been specially designed for students who want to learn how to visually display python data. On completion of the course, you will not only have gained a deep insight into the range of plots that you can create using Matplotlib, you will also be able to customize the plots to make them your own and ensure that they are visually appealing as well. You will also be able to draw attention to interesting parts of your figure using text and arrow annotations on the plot.

Meet Your Teacher

Teacher Profile Image

Dr. Gary White

Senior Data Scientist

Teacher

Hello, I am a senior data scientist from Ireland. I recently finished my PhD in Computer Science and I am hoping to teach classes that I would have liked to have had while I was a student. My research and teaching experience is in machine learning and data science. I also have experience working with distributed systems and now work in industry for a large tech company.

See full profile

Class Ratings

Expectations Met?
  • Exceeded!
    0%
  • Yes
    0%
  • Somewhat
    0%
  • Not really
    0%
Reviews Archive

In October 2018, we updated our review system to improve the way we collect feedback. Below are the reviews written before that update.

Why Join Skillshare?

Take award-winning Skillshare Original Classes

Each class has short lessons, hands-on projects

Your membership supports Skillshare teachers

Learn From Anywhere

Take classes on the go with the Skillshare app. Stream or download to watch on the plane, the subway, or wherever you learn best.

Transcripts

1. Introducing Matplotlib: Welcome to this course on Matplotlib, Python for data visualization. In this course, we go from a basic understanding of Matplotlib to be able to create really impressive visualizations. So at the beginning we start using simple straight line plots under different configuration options that you can use to specify the colour and line style of different plots. We then go through some of the basic blocks that we can use in matplotlib, such as bar charts, scatter plots, hexagonal been plots. Then we go through some of the customization and configuration options that we have in matplotlib. So basically everything in matplotlib can be configured an additive. We can change the title, the legend, whether we want a grid in minor tick label or Major Tick label, and even what color we want all of the options to be. So when the customization and configuration section, we go through how we can change each for each of these options. Then we go through the different style options that we have under stylesheets that we can use in Matplotlib to these stylesheets give you a really good default parameters for all the different colors and sizes of texts that you should be using. So we'll investigate which one of these is the best. We then go through how to add text and annotations to our plots. So if you wanted to point to a specific data point or a specific region are plotted and show why it's interesting. We can add a label and some text. We also show how we can use additional libraries to matplotlib, such as cartography, to plush geographical data, such as in this case the London underground stations. We also include a section on images where we can use matplotlib to pre-configured images. So if we want to create a circular end ahead, Josh, we can do that using matplotlib. And finally, we also go to seaborne. So seaborne is a higher level library that is built on matplotlib and which makes it easier to create the default plots and comes with some nice configuration updates to make pretty plotting very easy. So please join us in the course if you're interested in learning more about data visualization with matplotlib and Python. 2. Installing Matplotlib: We're gonna get you set-up with MATLAB Libby, and I have it installed. So if you go to the math postulated website, you can click on the installation link and this will give you all the information you need to install an official release. So you just need to install PIP and then you can pip install matplotlib. So if you're using Anaconda, you can do a conda install. So I'll leave a link to these resources in this section of the course. So if you have Conda installed, you can just use Conda install matplotlib. And if you have pip installed, you can just do pip install matplotlib. So another one of the resources that I include in the code is a PIP environment. So I find this a really good way of sharing the modules that I'm including when working on different projects. So it's just a list of all the resources and a log file for the specific versions. So if you go to the course and you open up the data visualization folder, you will see that you have this pitfall. And it just includes a list of all of the packages that are needed for the course. So mostly it will just be using matplotlib, which we do a dish of geographic plotting using kurtosis. And we also do some image editing, editing using a pillow. And finally, we worked on some seaborne plots. So if you want to use this Pip file, you can just install it by first of all, going to the folder. So in this case, I've exported it to my desktop. And then I'm just gonna do Pip, Pip environment install. So for this you need to add Pip Environment installed. So if you go to your website, they will give you all the information that you need to install it. And so to install all the dependencies, we don't just need to do Pip environment install. It will install all the dependencies from the pitfall that lock. So really Nicea touch all the dependencies have been installed. It will probably take a bit longer for yours because I've already tried this edge. And so then if we do Pip environment shell, it launches. The shell. Has built, been built from this virtual environment. So it's a sub-shell in the virtual environment with all of the modules installed. So if you do pip freeze, you can see that we have access to all the modules that I'm going to be using in this course. So CARTO P, matplotlib 3.2.1 and pi pandas. So basically everything that we need is installed here. And then you can use, you can run the Python codes from inside the shell and it will give you access to everything you need. So one final way is that if you're using pi term, you can go to phi term and preferences. And then you can set up the project and go to the project interpreter. So in this case, you see that I'm using this pi environment Pip environment, Bush. If you want to install any modules for this, you just click on this little plus icon here. And then you can search for the modules, then matplotlib, and then you can just install it here. You can even specify a specific version. So 3.1 to 0.1 or any of the other previous versions. So 3.1, but in this case it's good to use the latest versions. So this gives you a GUI interface. The easiest option is to either install it directly using paper Anaconda. But if you want to wait to automatically install all of the dependencies, then you can use this PIP environment. But make sure you've have PIP Environment installed. 3. Introduction: So in this tutorial, we're gonna get started with matplotlib. And the first thing that we're going to do is to generate a simple sign using D PLT Laplacian interface. So what we want to do first of all is to import matplotlib. So we import matplotlib as PLT. And this is just a convention that's used in Matplotlib to import images and PLD, like the same way that we import numpy as np. So we're actually also going to import NumPy as N B in this case, because we want to use it to generate some of the data that we're going to be plotting. So when we're working with matplotlib, we want to create a figure environment. And the figure environment is basically where all the information that is stored a better figure on what to use to actually generate the actual PDF for PNG image that's shown at the end of all the plotting. So the way that we do that is by using plt.figure. And then once we have our figure environment, Rican, start plotting some data to go. First of all, we need to create that data. So I'm going to create x-values that are linearly spaced between 010 being created one Tizen of those values. So this function, Yeah, just creates linearly spaced, evenly spaced values between 010. So it will give us a nice smooth blush when we're plotting ish in using matplotlib. Then we can use plt.plot. Our x values are the x values w and generate. And that should be POD. And then our y values aren't np dot sine of x. And so this is all we need to generate the actual block. But then to show the blush in this environment, we need to specify plt.plot Joe. And once we have dash, we can run this program. The way you can finish is by right-clicking and then hitting Run or by using this keyboard shortcut on a mock of control shift and, or. And so now you can see that we've been able to generate very simple first blush goes from 0 to ten as the linearly spaced data here shows. And we have 100 points. So it gives us a nice smooth, smooth curve. And we're just plotting a simple sine curve. So we're going to move on to cover a lot more complicated and build on this very simple starting tutorial. So we show how we can multiple different lines in the same blush and also specifying a lot of different options like line colors and line styles and axis limits. So stay tuned for those. 4. Multiple Lines: Okay, so in this tutorial, we're going to get started with plotting multiple lines. So you'll see in this tutorial it's really easy to add more complexity to your matplotlib plots by just adding additional lines and it's really simple. So again, we need to import matplotlib pyplot as PLT. And we're also going to import numpy to generate the data as np. And again, first of all, we create our finger environment by using plt.figure. And in this case, ruin of the sine and cosine of the x values. So first of all, we need to generate some x values. And we can use NP linear space again, regenerate the values between 010 and let's generate ten ties into those values This time give us an extra smooth curve. So in this case, we can then plt.plot the x values are x and as same as before, we can use np dot sine of X to generate the sine values. And then to generate additional lines, we just need to make some additional goals. We can do plt.plot again. Then we have x, we have np dot cosine of x. And then once we're finished generating all this data, we just need to show it. So again, we make to call into plt.plot o. And we can run this. And you see in this case we have the sine values on the cosine values. So at 0, sine 0 and cosine is one. So you can see that they are the, the proper values that are being generated for both of these waves. So this is how it's really easy to find additional lines and comes I could do to matplotlib. And you just need to make additional calls to plt.plot on. Then they will show on the actual figure once you call PLT dot show. So in the next few lectures we're going to go into a few of dissemble style options, like line colors, nine styles. The axis limits. 5. Line Colours: Okay, so in this tutorial, we're going to look at some of the line colors and style options that we can use when we're creating our matplotlib plots. So we've imported matplotlib as PLD. You import numpy as np ever figure environment set up. And we will also generate our x values using the linear space function between 010. So everything set up and ready to start plotting. So we can do plt.plot, mean ten of our x values. And we're going to use and B dot sine of x. And I'm going to put in a minus 0. And then we can specify what color you want to use. So we use the Americans pulling of color, and then we can just specify in whatever color we want to use. So in this case we're going to use blue. And I'll just show you this now to give you an idea of what it looks like. So we do PLT show, we run that. And so here's our simple figuring. So its equation intensive, looking blue. But there's a number of different ways that we can specify the color options for a figure. So if you hash Command Z or Control D on a Windows, it will duplicate the line. So in this case, I'm going to add in another value. Another way that you can specify the color is by using the color short code. So in this case, g is for green or would be for red. And so if I combine this, you can see that now we've got a blue and a green line, and they're both signed lots. The Greenland is shifted over by minus one. So we can duplicate this again. And another way that we can specify our color options is and by using grayscale options. So if we specify 0.05 and we change it to minus two, we can then run dash, and this gives us a grayscale. So 0 is black. And then if we change this to be the other side of the scale, and so it's a 0.75. We get a much lighter gray here. So that's if you want to keep your figure in a grayscale and type of color scheme will be a good method to use. So another way that we can specify our color is by using a hex code. So this is used lush in web development. So we specify the hash value first of all, and we use FF, add d, d 44. So this is just a specific color that I've looked at before this. And if we refresh, you'll see we get this sort of a yellowy color. So say if you're doing a data science project for a client and you want to have the figures that you're generating matching their color scheme. You can look on their website and you might get the x value. And then if you generate your plots using that x-value will look really good. So it just adds like an, a personal touch to figures are personalized to them. Or if you have your own sort of broadening scheme, then you can specify your own. The final way that we can specify colors is by using an RGB values. So in this case, so it's an RGB tuple. So we have 1.00 as 0.20.3. And we don't need these quotations. And if we run that he's II, we've overwritten the last value. So combine again. So we get this sort of red value and that's what we expect because we're using 7x, one of read a small bit of or green and then a small bit of blue. So it's mostly a red diagram. So you can see here, we're able to specify our colors in a number of different ways by either using long form spelling on by just their shores from channeling. So we can specify blue here by just typing B and then running. And you see this gives us the exact same blue color. So there's lots of different ways to specify your color. And later on, we'll look at some specific color schemes that we can use, which we'll choose declares automatically for us. 6. Line Styles: So another option that we can specify when we're creating our plots is the line style. So we've been using the solid line style has over. So there's no dash, dot, dash lines in any of these figures. We've just been using T solid line. So again, we've imported matplotlib numpy by a refigure environment setup, we have x values created using underneath Space values between 010. And so we're going to set up using plt.plot. And we're going to use the x values. And then I'm going to plot x minus 0 as the y values. And we're going to specify the line style. And in this case, we're going to let that equal to solid. And I'll just run that to show you. So here we have a solid line and linear. So the x values, x and y values are also x minus 0, so basically just the same as x. And so we're going to duplicate that. And I'm going to specify in the next line some of the other options that you can use. So another option that you can use is dashed. And so if you run this, you see that you get this dashed line here as opposed to just the solid line. So this can be useful if maybe some early results are for differentiating some and different results in the legend. And we'll get to that later on in the course. So at the minute, it's just giving you an idea of some of the different style options that you can have in matplotlib. So another slightly different dashed option that we have is dash, dash. So if we run lush and I plotted over there, there anyone. So I'm just gonna give you a better idea. So you can see here we have a dash, then we have a dash, dash. So there's just a slightly different variation on the original and dashed line. And then one of the other options that we can use is a dotted line. So this just contains all the dots I plotted over again. So if I change it up, then you can see the different sort of line options that we have. So we have our solid line, the dashed line, d dash, dot line, and the dotted line. So this can be a useful way, as well as the colors to differentiate different values that we're plotting. 7. Axis Limits: Tutorial, we're going to look at the different axis limits that we can specify in our plots. So we have all the usual standards of mortage. We've matplotlib numpy and set up our figure environment. And we have our x values that are linearly spaced from 0 to ten. So we can then plot the values using plt.plot. And we plot the x values, are going to use them by sine of x two then plot to sign up those values. So the way that we can specify the limits is by using d y limb function. And this will specify wash. We want the limit to be in the y axis. So in this case we're going to go from minus 1.5 to 1.5. And we can also specify the x limits and by using this interface. So if we use PLT thought xn, we can specify the limits three from minus1 to 11. And then if we show this using PLD that show, you can see now the x-axis has been stretched slightly, so it doesn't just start at 0. We have some space in between here. And Rialto also space at the top, on the bottom of the figure. So do show dash or to show the differences a bit more clearly. I'll specify another figure using M, plt.plot SSH. And then we're going to use x and b dot sine of x. Tier. I'm going to use plt.plot axis and I'm going to specify t's a tissue layer. So this m do useful option to specify in your figures. So it tries to reduce the whitespace as much as I can. And then if you use PLT dot show, you'll be able to see the difference in this and the previous figure. So here you can see that we have a lot more white space on the figure is a lot more compressed compared to the updated figure. How to close here. So here you can see where we're going from this figure that has a lot more whitespace to this figure, which is a lot more condensed. So we can specify the axis to be whatever we want. So if you want 110, we can see how that looks. And you can see here our x axis has got stretched and relearned to 110. And so it's only taking up a very small bit of the figure compared to when it was here. So you can specify whatever you want. Bush using this plt.plot mustache is a pretty good em, just general configuration because it will try to reduce the whitespace as much as possible. 8. Saving Figures: So in this tutorial, we're going to specify some of the options that we have for save and figures. So once we've actually generated the figure and matplotlib, we usually want to display in neuter, an article or a presentation that we're giving. So there are a number of different options that we can specify to generate a high-quality figure as an egg push. So as usual, we've imported matplotlib, numpy. We've set up our figure environment. We've generated dx values that we're going to use, which are linearly spaced from 0 to ten. So in this case we're going to just plot a simple function using plt.plot e x values. And then we're going to use them by sine of x. So first of all, we can specify the different options that we have for generating our plots. So we can print fig, Canvas, dash, dash, underscores, or did file types. And if we run that, we can see that we get this list of supported file types. So we have postscript. Yeah, I've encapsulated postscript, PDF, PDF, PNG wrong at tiff, JPEG and SVG. So basically all the major ordered file types, you're able to save your figures. So the first figure that we're going to save it as a PDF. So I would usually use PDF for most of my fingers. And because it's a vector-based format, so it's infinitely scalable. And I'll show you the difference between some of the plots, the different options that you can specify as we go through the tutorial. So Dwayne, we save, which is pretty simple. So you use PLD, that same fig. And then you just specify the file name which want to use. I'm just gonna use colors, PDF. And you just need to specify the file type. And it will automatically generated. So if we run that, you can see now we get this colors dot pdf file. And if we double-click an edge, you can see that we've generated our diagram. And if we zoom in, we see that it's infinitely scalable. So even if we're zoomed into an 800%, all of our figures look at 3D crisp and there's no like pixelation. So the next file format that we can use, SAR node or one that we can use is that's quite popular, is P&G. So again, we do, I can just duplicate that previous line and change it to PNG, e and g. And if we run this and open, you can see we have our PNG file. But one of the things is that if you zoom in, you see that there's some pixelation compared to what we had in the PDF file. So one of the options that we can specify to improve this slightly is the DPI or the dots per inch. And if we specify dash equal to 300, it will improve the pixelation. Someone here and again, we can open it as image. And you see now that it's not as pixellated as it was before, you can see that if you zoom in really far and it will give some pixelation. But it's not as bad as it was before. So you can also specify edge a bag, soil using PLD saving. And we can just use colors. Bush JPEG, JPEG. And if we run this and see now we have our three different file types. So we've colors dot j, dot PDF, PNG, because we haven't specified. I need dots per inch with TBI, with JPEG, and Xena to pixelate is quite large. And so just to give you the comparison with the PDF, now, if you go back to this, you can see that there is no pixelation no matter how close we get. So that's why I like using PDFs. Because you get this infinite scalability. So you should try and use PDFs as much as he got in when you're generating these figures, especially if they're gonna be in published articles. 9. Matlab Style: So in this section we're gonna go over that matplotlib architecture. So there's two main interfaces that you can use for interacting with matplotlib. You can use the MATLAB style architecture that we're going to go over in this lecture. Or you can use the object oriented style M interface that we'll go over in the next lecture. So the mat lab style is more stateful based. So it's usually used for hedging the simple plots, but Academy quite effective as well for creating some slightly more complicated plots. But the object oriented style and a stateful. So it makes it a bit more easier if you have a lot of different axis and figures that you're working mesh. And so for a slightly more complicated plots. So we'll go over as well some of the different axis options that we can use. So if you want to craft multiple axis in the same figure. And so that's basically what we're gonna cover in this section. Okay, so the first thing that we need to do when working with matplotlib is to import matplotlib as PLT. And we're also going to import as np to generate the values. Then we're gonna create our x values, which aren't going to be d linearly spaced values between 010100 of those. Okay? So D structure is still basically the same. So we create our plot figure, writing plt.figure. And then we want to create the first of two panels and set it to be the current axis. So to do that or creating a subplot. So we do PLT. So we're going to create our first sublist. So the values that we're entering, our 211. So two is the number of rows, then we have the number of columns and then the panel number dot we're working mesh. So in this case we're working with the first panel. And we're just going to plot where first figure in this panel. So we do plt.plot. You're going to use the x values, then num pi, thought sign of the x values. So this is going to create a sign M diagram in the first sub lush. Then we want to start working with the second model and set it as the current axis. So we do PLT dot, so blush. And it's the same rows, columns. And then we're going to be working with panel number two. So the last number is the panel that you're working with. In this case, we're going to work with the second model. And in this we're going to plot the cosine. So plt.plot. And then the x-values by dot cosine Elise. And then once we have this, we can do PLD that show. And then we can run this. So you see here, this is what we're getting, where you have d2 axis and the first one plotting the sine value. And so you can see at 00. And then on the lower, so blush, we have, we're plotting the cosines so 0 and has a value of one. And this is how we can divide up our figure and to have multiple different subplots. So this is the Matplotlib are the sorry, MATLAB and interface. So I'll show you the difference in the next lecture of using a more object-oriented style interface. 10. Object Oriented Style: Okay, so in this section we're gonna go through the object-oriented style interface that we have for matplotlib. So we have imported matplotlib, we have and we have our x value is all set up and ready to go. So the first thing that we want to do is to create our creative plots. And so we can do by having fig and axis, then creating document of subplots that we want. So in this case we're going to have sub-bullets too. So it's going to be similar to the diagram that we created before using the matlab style interface. But we're just going to see the different ways that you can interact with matplotlib. And so we wanted to call am block on the first axis. So we can access dash by doing a x 0. So 0 gives us access the first axis. And then we can call blush. And we're going to push x and pi sine of x. And then if we want to get access to the second axis, we can use a x one. And then in this case we're going to push x cosine of x. So we can use PLT dot show to show this. And you can see we get the exact same figure that we had before. So you can change the amount of subplots that one quite easily. Switch on top tree subplots. You can just add tree here. And you say we don't have anything into finals or blush because we haven't plotted on cash. But it makes it very easy to change the Manchus doublets and then it's not stateful. So you can just draw figures on axis 0 and x is one. And then when you call plot that show, they'll all be compiled and drawn together. So you don't have to work on one axis. And all at the same time, you can add some different configuration options. And so if you want to have multiple different figures. So say in this case we just have m one axis, dots going through three different rows, one column by three rows. But if you want to have multiple rows and columns, but you can do that as well. So if you have fig and then we have a tuple, which axis, one? Axis two. We can use PLT plots. And we can create a two-by-two sublevel. So then we can use say X1. Posit the 0th index. And using this axis, we can then flush the x-values, NP, that's sine of x. Then we can duplicate that. In this case, we will plot the cosine on the first, next, first indent of axis one. And we can duplicate this again. Then in this case we're going to on access to the same thing. So sine and cosine 0 on one. So it makes it really easy to guess and access to both the axis. And we don't have to work in these stateful approach. So if you do PLT dot show and see what we've created. So here you have, in this case, we have air supply of two-by-two axis. We've plotted the sine value in axis one at 0 volume, and then in t axis one, d first volume. So this diagram over here, we have cosine and we've plotted cosine on both of these. So you can change that to be signed and run it again. And yeah, you can see now that we have sine and cosine on each of the two different diagrams. So using the object-oriented interface makes it really easy to add more columns to the diagram. So in this case we have two axes, but if we wanted to have four plots in each axis, and we can just change the hash. And then once we compile it, we have access to the four columns over two different axis. If you want to add more axes, you can just X is values here. And that will give you the additional rows. So it makes it really easy to generate these complicated blots went lots of different subplots by using the object-oriented style interface. 11. Twin Axis: In this tutorial, we're going to go through training and axis. So this is where you have multiple blocks that you want to show on the same axis. In this case, we're going to show an ex, financial posh and a sign block. So we have the usual setup where as you go we have imported matplotlib. We've set up our mock data. So it's in t, which is time series. We're going from 0.1 to ten in 0.01 increments. And then our data one is the exponent of t on our data too, is the sine of two times pi times t. And then we have our figure axis one setup. So now we can start creating our plots. So in axis one, we're going to plot d t values, then data one. And we're going to set the color equal to red. Then to twin the axis. It's actually quite symbol. So we can just say axis two is equal to i axis one dot twin. And this gives us a twin of the switch would be 2x to give us a twin of the x-axis. And then once we have between the x-axis and we can plush on access to, so x2 dot plot. And then in this case we're going to plot T D data to do, we're going to change the color to blue. And so then we can do PLD that show just to show what we've setup so far. And you can see here we have our sine values that are plotted using a x2 Laplacian, the colors blue. And then we have our exponential bodies that are plotted in the color red. And you can see that we're sharing the same X i, x, x axis. So we also might want to update the labels just to make it a bit more obvious to the readers. My each value stands for. So if we sash X1 dot, we can use the sash x label. And we're gonna set that equal to time. In this case seconds. We're going to sash dx1. We're going to set d y label. We're going to set that equal to exponent, so EXP. And then for x to access to, we can do the same. So we say the axis to y-label. We can set that equal to sign. And if we run this, oops, made a slight mistake there. So you can see here we have the exponent values am. And actually one thing that may be good to change here would be to change the color. So when someone's reading this, they're probably not sure. Well, you can probably guess that the exponent values are going to be the higher values. But we can change the color just to make that a bit more clear. So we say color equals red. And for this, if we update the color three equal to blue. So you can see here now our exponent label here is red. So users will know that this axis corresponds to T read value here, and this is blue, which corresponds to the blue axis here. So another thing that we could actually do that I'll go over in a bit more detail in the later lectures is to update the tick parameters. So if we do x1 dot tick, just to make it even more clear. So we can set the y-axis, change the label color equal to red. And then we can copy not to change it for x2. And if we run that, we see now that we've changed these tick parameters to be equal to red as well. On these take parameters to be equal to blue. So this is the way that we can use the same x-axis to show two different plots. And then by using these color configuration options, it makes it really clear which part of the diagram belongs to which part. 12. Gridspec: We're gonna go through the GridSpec class. It gives us a lot of em, release the options that we can use for formatting. If you want to have a lot of different axis in the same figure. So we've imported matplotlib wi Bosch as usual. And in this case we're also importing matplotlib dot GridSpec. We're importing this GridSpec Greeks GridSpec class. So if you hover over something in Python, you get a bit more information about it. So you can see em grace a grid layout to place disciplines when at a figure. And it just gives you some of the options. So we've also set up the figure environment and using plt.figure. And I just have this simple function dash will label the different axis just to make it easier to see what's going on. So we set up our GridSpec as gs and then recreate our GridSpec class and integrates fat class. We're going to have a tree by tree axis are going to set up our figure as fig. So in the first axis, we can specify X1. We can set that equal to M fig dot-dot-dot sublist. So we're going to add a sub blush. And then this is a blush. We're gonna go from GridSpec 0 until the end. So this will give us one complete access. And do you specify the end? You use these two dots, so a colon. And just to show you what's happening at the moment, we can do PLT the chill and run this. So you can see here we have our tree by tree axis. And in the first axis we're adding this simply push and we're going from space until the end. This gives us one complete axis. And if we want to add a bit more complexity, we can have another access called AX-2 and we can do a, another figured out ads. So blush. So I'll actually, I'll just duplicate this and change this to AX-2. And in this case we're gonna go from one. So this is the 0th row, the first row. And we're going to go from one up until space too. And so I can add in the format axis. And we're going to format the axis in the figures based on that, we'll just show you what's going on. And so if we run this, you can see now where our first axis, that isn't the 0th row. And then this axis, which goes on the first row up until the final space. So if you think of this in columns, it's like 0 is here, 12. So we're going up until two. And then we can just start filling in the different axis, axes that we want. So we can have a X3 and X4. And I think we're going to have five axis altogether. So 345. And so for access tree, we're gonna go from one until the end. And then we're for the Coulombic, we're gonna go to two. So it's going to go from one. So this first row here, and it's gonna go all the way to the bottom to include two. So it will, you'll see at the end what it looks like exactly. And then for access for where you're gonna go from two to 0. So we're going from the second row and we're just going to have this access, the 0th position. And then for access five, we're going from the second row, and we're just going to have this in calling position one. So x is tree will come down here. This space, because it's going from the first row until the end. And we're using the column two. So remember in Python we go 012. So that's why even though we have a tree by tree axis b go from 0 to two. So if I run this, you can able to see it better. So as you can see, it's filled in as we expected. So we have access tree here, it's going from and the first row until the end. So that's what these two dots that colon here mean. So go from one until the end. And in this case we're using the second column. And much is well at the index to volume, which is the third gallium. And then for access foreign five, we're going from the second row and we're filling in on the first column. And you can see all these axes are labeled. So this can be a really easy way to set up some sub-bullets If you have quite a complicated figure. But I would advise trying to keep your figures as simple as possible, at least in the start, and to only have maybe one or two different axis. If you have five different axes and your figure and probably shouldn't be a really good reason why. 13. Adjustable Axis: So in this tutorial, I just wanted to give a quick guide to the axis can be changed by setting the adjustable option. So in this case, I've set everything up and we have imported matplotlib setup or figures. We have two different axes. We have a X1 and X2, so they're plotting the exact same values. We've set d, x scale and y scale to be login, Both of them. We've set the x and y limit to be the exact same botulinum, and we've set the aspect ratio to me the exact same. So the only thing that we've changed is to set this adjustable parameter to be different. And so change how it's defines which parameter axis will change to give an unequivocal aspect. And it can be set equal to Box or data limit. And so in pi term, if you hold Command and hover over this, you can click it on it. On, it will bring you to the definition. So if box is we'll change the physical dimensions of the axis or if data limb, it will change the x or y limits. So this is the only parameter that's different between them when is set to box and the iterates at Tunisian limit. So if we run this, we can see how that changes. So for a DI box, you can see we've actually changed how the box as being laid out compared to D data limit, where we're just changing the axis definitions. But the box is actually changing the size and scale of the box. So it's just something you can be aware of. If you're wanting to preserve an expert aspect ratio. You can set this parameter to either follow up the box or to change the date limit. 14. Axis Zoom: So in this tutorial, we're looking at an axis zoom function that we can use. So if you look at the diagram on the right, you can see that we have a larger figure which goes from 0 to five. And then it is zoomed in to specific portions here, which go from 0 to one and from two to three. And we see that there's arrows pointing to make it clear that these are the portions of the figure that we're zooming in on. This. Can we go to few some really interesting piece of information here? Or you want to specify why the reason is that you're getting the results here. So as usual, we import matplotlib as P Y. Then we create our figure environment. We set up an axis, one, axis one as the two by two by one. So two rows, two columns. Then it indicates that we're working on axis one. And axis two is at the second column and the second row, but we only have one column and access to. So access to, we set up the limits. So this is the bigger figure here, which go from 0 to one. And then from 0 to five. Then we use this function called zoom effect is 01. And this creates the zoom effect between 0.20.8. So we can change these values and show how it updates in the figure. So if we run that again, you can see that the values have now shifted over a portion to go to 0.830. So the main parameters for the zoom effects here, one are the two axis. Then we have the X-Men and Wyman. It's a bit more complicated to do this function and it involves a lot of blended transform unbounded boxes. Bush the idea. And with just to show you that this sort of figure as possible. And that you can create these areas with zoomed in points that you may want to add, do some further analysis on. So you can use these functions in Twitter on zoom effect 0-2. There's something quite similar and there's a few different options. You can see it as arrowheads. And it's just contained the actual full data. So there's no whitespace in the fingers all bush. This tutorial is sort of more just to make you aware that you can do these different zoom effect options. So maybe something you might want to look into if you have to have some additional explanation for a specific portion of your data. 15. Scatter Plot: So in this section we're going to get it started with some of the basic blocks in matplotlib will start with some scatter plots and density plots, histograms, 2D histograms, some kernel density estimation plots, as well as some bar plots, box plots on pie charts. So these are all just sort of standard plots that you would expect to be doing it on a sort of graphing application. I'm going to show you how to do them in matplotlib. So the first thing, as always, is to import matplotlib dot PUI plush as PLT. And we're also going to import as np to use for our data generation. So we're gonna create our x values. They are going to be linearly spaced values between 0 and n. And we're going to create 30 of them. Are then going to specify our y values, which are going to be equal to the sign of the x values. And so to create our posture and use plt.plot. And we're gonna specify our X values or y values. And instead of plotting a line, we're going to plot use a lowercase O, which is gonna use dots and the blush, as opposed to creating one line scattering of lower dots fronted than one continuous line. And we can also specify the color and let it equal to black. So if you do PLT plots show and run that you can see now we have our scatter plush with lots of individual dots rather than the continuous line. So there's lots of different options that you can specify in here. We're gonna go in the next tutorial with the different scatter markers wi. So I'll show you that. Fish if you wanted to, you can change the number of dots to 20. And this will give us less dots intellectual side Bosch. And if you wanted to have a continuous line, you can use a dash here. And if we increase the number of points to say 200, it gives us a nice approximation of a sine curve from 0 to ten m. So this is how we can get started with scatter plots. You just need to change this to lowercase. So, and that will change from a line to a continuous series of dots. 16. Scatter Markers: Okay, so in the previous tutorial, we got started with a simple scatterplot. And we've seen that there was a number of different options that we could choose. So we had the lowercase O that we use to create the dots. We can replace this with a number of other options. So in this case, you can see the full list of different options that we can use for our marker. So we have the lower-case o, we have a dash comma x plus b. We have a carat symbol. We have a bracket, left bracket there, I, S and D. So S and D stands for square and diamond. And so I've already run this. So you can see a diagram on the right. And you see that S and D stands for square and diamond. These brackets are the triangles which are pointing to each side. The carrot, it's binding up the v pointing down. And we have a plus symbol, which is using the marker on rails-api x using the XML marker. So the comma is this really small point. It's very hard to even z. E is a slightly larger point, then the o is the big point. So you can see that there's lots of different options to use for the type of partner that you want in this kinda plush. And there's also some other options that we can set, so things like the color and the size, which we'll get onto in the next tutorial. When instead of using the plt.plot command, we're going to focus on the PLT dot scatter command, which makes it a bit easier to set some of these options. 17. plt.scatter: We're going to talk more about using plt.plot data instead of plt.plot. So it's a specific function that allows us to specify a number of different options when we're creating our scatterplots. So if we hover over it in by term, we get a bit more information. So we can see that it makes a scatter plot of x versus y. We're specifying our x and y values here. And the marker size is called, is scaled by S and the market colour is mapped to C. So you can get a bit more information about these bytes. So it expects a scanner or array-like shape. And for C, it's a color or sequence or a sequence of color. And it defaults to be. And you can also specify a number of the other standard options that we were changing using plt.plot. It's now can be things like the norm, add a marker. So what market style you want to use, you know, setting the minimum and maximum of the plot size. So in this case, I've imported matplotlib and up PMI push with PLD. I've imported num by, and I'm also going to generate some random values using this random station. So for the x values, it's a range of random values and using around n, which specifies random values from the standard normal distribution. And we're going to specify when hundreds of those values, and then for the y values, are going to specify another 100 values. Then for the colors and sizes. And we're also going to use this range around the values. And then all of the function plotting is going to happen in this one call. So using the plt.plot gutter, we specify the x values, the y values. We set the color equal to these random values. Colors, reset the sizes. And so the alpha value, say transparent, the actual m dots will be. So if there's any overlapping points, you'll be able to see that there are overlapping rendered and, and just being solid points. And we're using the Redis Colormap. So we also wanted to show the color bar. So we use the plt.plot on that will generate it next to the plush. So if we run this, you see here the, the actual dots are transparent. So we can see when this sort of yellow point is hidden behind these purple points among these are overlapping as well. Because the alpha value is set to 01 tree. We can also see how the colors and shapes are changing based on their own values. And we have this color bar to the side, which is showing what the, what the actual colors represent. So this is just using random values Bush, I also wanted to create a bot that using some actual real-life values. So we're going to load in a Iris dataset. So this is a really famous data session and machine learning. Which is a bash and plants. And you need to have SK Learn installed. So make sure that you've installed all the prerequisite modules. And I specify at this data for the course. And you'll be able to load this in. Okay, so from SKLearn groups, from SKLearn dot datasets, we are going to import T load Iris dataset. Then we're gonna specify our iris by creating an instantiation of load Iris. And once we have done, we want to specify our features. And the features are going to be equal to the iris data dot transpose. So we can then set up our PLD, that scatter plot. And we can specify our X and Y values. So this is what the features are included in the load Iris dataset. So we have the sepal length, sepal width, petal length, and petal width. The species. So the sep I'll plant is sort of like d, d green covering that comes over the petals. And so we have the length and width for the sepal on the pedal and be able to have the species. So in the plt.plot Center, the first thing we're going to flush is feature 0, so E sub, All right. So features. And then we're going to up the second features. So features one. We're going to specify slash V0 alpha is equal to 0.2. So just to allow the points to overlap, like we have in this diagram, the size is going to be equal to 100 times features tree as the color. We're going to specify the species. So we'll set c equal to Iris dot target. So this is the target you're usually trying to specify in machine learning problem, which is the actual species. So then we can just update the axis to make it a bit more easy to read. So the x label is equal to the Iris dot feature names, feature name 0. And the y axis is quite similar. So we specify the y label. And we said that feature names one. And then we can use plt.plot Hill to shore up blush. And so as you can see here, we have the color specifying the target of the labels. So this is the species. So you can see we have one species here which has quite a small sepal length and sepal width is quite large. And then there's three species and total, we have this purplish species, this yellow one and this green one. And you can see how the sepal width and sepal length can be used to help to distinguish between each of them. So that's how you can use PLT that scatter the options that you can sash by changing the color and changing the size of the actual points. 18. Density Plots: Go True density plots, which are sort of like a topographical maps. So you might have seen them in some mountainous regions where you have lots of lines that are close together and they showed the equal parts of elevation. So if you're going up a mountainous region, you'll see that there's lots of these circuit lines close together showing the elevation is rapidly changing. So I've imported matplotlib numpy. I've created this function f, which takes the x and y values and returns a value that we're going to use for our elevation seduces the sign and it goes on. And then I've also created D, X and Y values by linearly spacing and between 05. So we have 50 x values and 40 y-values. And then I create a mesh grid using Numpy. So the mesh grid returns coordinate matrices from coordinate vectors. And so this is used to create our little coordinate system that we're going to use in our plots. And then the z function for our elevation. It just uses at the function f on the X and Y values. So the way that we can create these density plots in matplotlib is by using PLD bought contour. And in the contour, we need to specify our X values or y values under z values. Then we also need to specify the number of levels that we're going to have in our plush. So in this case we're going to use 20. And then we're also going to specify the color map. So we can do that by specifying schema up. And we're going to use the color map of or D, G, and Y. And then we can just do PLT dot show to show what we've created so far. And so you can see here, we have this density plot and it's showing the elevation in these different points. So we can see that there's rapid change in elevation here where there's a lot of these points are close together. Because we have 20 points. We're seeing quite a difference in changes. So we put that down to maybe five. We can see what effect that would have. And you can see now we have a lot less information because we only have five different levels. But we can still see that there's quite a bit of change here. And here. It's just that we're not getting as much detail. So we can put that back to 20. And so one of the other options, though we can specify am, is to use to add the color bar as well. So we can use PLT dot contour, F. And we can specify all the same. Buddies. And Rican use PLT, dark-colored bar to show the cover up decide. And if we use PLT, but she'll reach and run that. And you can see now that we have this colorbar at the side. And instead of using contour, we're using contour f. And so this just gives us a slightly different contour plot. That's rubbish, more shading. So it's not quite as there's not as much whitespace and it tries to like fill in the gaps. And so you can see the different stare. And we've also got access to this color Barrett decide sewing word the low values are. So we can see that we're going into a bit of a valley and these points that there seems to be an increase or in this region because that's where the point stuttering near one. So there's lots of other options that we can specify. So we're going to create another contours. And we can set that equal to PLT contour. And we're going to use the same values again. So the x, y. And this case we're going to go and have three levels. And we're gonna specify the colors three equal to black. So in this entrepreneur sh, we're going to use slightly different labeling. And it will have the labels are actually on the blood. And so we'll be showing the elevation rather than having the colorbar at the side. So we're going to use PLT dot C label. So this is the contour labeled. And we need to specify the contours. We're going to use specify inline is equal to true. And we can set the font size equal to eight. So once we have that done, we can use PLT dot show to show how this changes the labeling. And if we run that, you see now that we have the minus 0.06 and it's actually being shown in the plush, rather than using the color bar on the side. We can make this a bit more pretty and, and take away some of the whitespace by using the plt.plot function, which fills in some of the void space. So we need specify z. The extent that we want to fill in, which is a list from 0 to five. And then 0 to five. Because it's a square box from 0 to five, we're going to fill in these values. And the origin is lower. And we're using the same c equal to d, G, y, and alpha is equal to 0.5. so if you remember that, you can see here, we're using the inline plots. We know when the elevation goes to 0.06, in this region, it's 0 as 0. And in here we're going into the valleys where it's minus 0.6. So we can also add in a Collobert just to show what the colors mean by adding in PLT thought color bar, as we did in the previous plot. And if you run that again, you can see now we have the information being shown both on the map of what the elevation is, as well as using the color variant side. So here you have treated for an options that you can use to specify the density plots. And they can be really useful for showing elevations or something like that. So you can have this sort of basic block, a lot of whitespace. Then you can turn to fill it in and used the covariate that side, which is a bit more intuitive. And then you also have this option where it specifies the actual elevation in the plush. 19. Histograms: Okay, so in this tutorial we're going to take a quick look at using histograms. So histograms are a really good way of giving you a quick overview of the distribution of your data. So it shows you is you have a number of outliers or where are the most amount of points are in your data. So we've imported matplotlib as PLT. We have numpy as np. So we're all ready to go and to start generating our data. So we specify our data as np dot random, dot random. So we're going to generate some random values from a normal distribution and we're going to generate 100 values. So the way to use a histogram is really simple. And matplotlib, you can just use PLT test. And if we do PLD that show, you can see the ash with. So we need to specify the data that we're going to use in our histogram. So it's not quite that simple. But so we specified the data that we're going to have in our histogram. In this case it's data. And we're specifying values from a normal distribution. So we can see that just using the default parameters, we got equation and good looking diagram, histogram diagram that we can use to show that indeed our data is drawn from a normal distribution. So there's also a number of options that we can specify in our histogram. So if PLT, we can specify the data. We can also specify the number of bins. So this case we're going to have 30 bins. So like in a number of the other plots, you can specify the alpha value. And if you're using pi term, you can see that it's giving us a list of the optional values that we can have in this function. So we're gonna specify the Alpha and we're gonna set that equal to 0.5. So that's the transparency. And it can just make it look a bit more nicer. So we're also going to specify the type. And in this case we're going to use a step filled step filled histogram. And we're also going to specify the color. So in this case we're using a steel blue color. And you can also specify the color of the edges on the way that you do that is by specifying edge color. So edge color is equal to, and in this case we're going to use none. So we don't want it to happen edge color. And then we can just use plt.plot L. And if we run it again. So I misspelled steel, so STL still blue. And if we run that again, you see now that we have our steel blue color. It's more transparent, so the transparency is set to 0.3. We also have a lot more bins. So you can see here, there's quite a lot of steps between them because there's not many bins. Bush, by increasing the size of the bins, you can see that it starts to form to follow a more normal distribution. So if we wanted to have a number of histograms in the same block, we can also do that. So we need to generate some new values. So x one is equal to np dot random dot normal. So we're going to use a normal distribution and we're going to use 00 h. And we're going to generate 100 values. And we're going to make these to be slightly and three centered around slightly different points just to make it clear in the diagram. So we're going to use minus2 and centers. And so we're specifying the mean and the variance for each of these. So mean of 300 myriads of two. So if we look here, you can see the options that we're specifying for D, normal distribution. So the mean and standard deviation. So if you ever want to get more information about something and num, num by just total command and hover over the function name. And it will bring up the more information. So the way that we're going to pass all the arguments into the different histogram plots is by setting up these key k works. So keyword arguments. And we're gonna set up a dict. So it's just a data structure in Python. And we're going to set t his type two. Why P is time to be equal to step filled? Sash alpha equal to 0.3 and set the bin is equal to 40. And now we're just going to plot our histograms so you can use PLT. And we specify X1. And then we're passing in our keyword arguments. So you do star, star, keyword args. So we need to do this when we're passing in a dictionary to specify our keyword arguments. And then we can just duplicate this and replace the X1, X2, and X3. And then we use PLT. Let's show to show what we've created. So now you can see the different histograms that we've created. We have d values, this one centered around minus two d. So that would be dx2 values. The x one values are centered around 0. You can see it's slightly tighter. So distribution because it's set to 0.8. And then we have the x T values which are centered around tree. And we can see these are slightly wider because it said 22 here compared to 0.81. So if we increase that to tree and we can see what effects it has, and you can see that it gets spread ash. And so the reason why we have the alpha equal to 0.3 is so that we can see when there's overlapping between the two points. So that's how you create a histogram. You can have quite a good histogram just using the default options. And then you can specify what his type you want and the number of bins. And you can also combine multiple different histograms into the same figure. 20. 2D Histrograms: This tutorial we're going to be looking at using 2D histograms. So it's basically just the next step after looking at the previous tutorial on histograms. And now we can include multiple histograms and a single blush. We can also create two-dimensional histograms. So I've imported matplotlib and number has 200. And now we're going to create our values. So we are going to sash mean equal to 00. And we're going to set the covariance equals to a list. The first item in the list, it's going to be array of one, dash one. And the second item is going to be one. So this is the mean and covariance that we are going to use when we're creating our 2D histogram. And the values that we're going to have, our x and y. So we specify x, y equal to NP dot random multivariate normal. And in the multivariate normal you can see we're specifying the mean covariance on size. So we specify the mean, the covariance and we want 100. Then we're going to transpose this. And then we're going to create a 2D histogram. So we're using PLT dot hist 2D. And indeed to the histogram, we need to specify the x and y. Then, like in the previous histogram tutorial, you can specify the number of bins. In this case, we're gonna set it equal to 30. We're going to set our colormap equal to blues. Cmap equals blues. So this is just a range of different blues colors that we can use when and creating the plot. And then we can set up our colorbar using CB equals VLT, that color. And we can also set the label. So see me, dodge satellite. So sash underscore label. And we specify that to be equal to b. And we can use plt.plot o just to show what we've created. And if we run that. So now you can see this two-dimensional histogram. And we have the contents in the bin for each of the different points in the axis. So you can see at, around the central point here, which is what we would expect when they both have mean of 00. So the covariance is slightly different for the x and y values. And which is why it's sort of diagonal as opposed to being centered. But we can see as we would expect, that the largest number of points, Iran, the 00 mark. So we can also create a slightly different blush and it's using a hexbin. So if we do PLT dot hexbin, where you can specify x, y, the grid size. And in this case we're going to set the grits iss equal to 30 and the CMAP blues and the colormap blues again. And then we can specify the Klemmer. So the polymer equal to PLT ever. And then you specify label is equal to k2 inbun. And once we have created, we can do PLD that Joe. So the hexbin is very similar to the to the histogram Bush. It's just using a hexagonal shapes. So you can see here, these are each hexagonal shapes as opposed to the squares that are created in the 2D histogram. So it just gives you a slightly different variation on the 2D histogram. And it makes it look slightly cleaner. It can sort of look a bit pixel editor blurred if you're using this, but the hexagonal shapes, it makes it looks a bit and bit more cleaner. So you can choose either want to use a essentially do the same thing. So you can see that again, centered our end 0-0 is where we're getting most of the kinds into bin. For both of these plots. Dangerous, looks like indifferent. So that's our 2D histograms in matplotlib. 21. Kernal Density Estimation: So another way that we can calculate a plot similar to the 2D histograms on the hexagonal been blots is by using the kernel density estimation. So in this case I've imported matplotlib numpy, and I'm also using the Gaussian KDE function from sipeoyo dot-dot-dot. So make sure that your psi by installed to use this program. So the Gaussian KDE is a representation of kernel density estimation using Gaussian kernels. So basically estimates the probability density function of random variable in a nonparametric way. So certainly as similar to what we had seen before. So I'm just giving you a quick overview of vision in this tutorial because you can already use the hexagonal bins and you 2D histogram. So it's the same as before. We set up the mean and covariance. We set up our x and y values. Then in this case we're instantiating the Gaussian KDE on the Ngozi and KDE function on the data. And then we set up our grid and elevation and then plot the results to an image. So if you want more information on it, you can hover over and click the guys can gaiety. And so it's essentially a way to estimate the probability density function. So if we run this, you can see it's giving us something which is quite similar to the hexagonal been plots that we'd seen before. So if I just closed from these, so it's giving us the probability density function for this dataset. And you can see around the end 0-0 values, it's quite similar. And because they have slightly different covariance, it's giving us this sort of diagonal shape. But you can see it's quite similar to the hexagonal on the 2D histogram plot. So there's lots of options if you want to get sort of a probability density of the way that your data is. 22. Barchart: We're going to be looking at bar charts. So bar charts are one of the most popular charts that you can use for looking at data. They appear and a lot of different papers and presentations. So as usual, we need to be the first step which is importing matplotlib as PLD. And in this case we are going to generate some simple data. So we're just going to have a list of values, which is going to be 5255020. And we're going to create a bar chart to plot these. So the way to create a barter is pretty simple and we can use plt.plot. Oops, I'm Care. Bear. And the options that we can specify. And first of all are the amount of values dash we want to have in the bar chart. So we're going to do that using the range function. And we're going to give us the length of our data. So this will be the magnitude pairs we're going to have in the actual barplot. And then the data is the data that will be used to calculate the IJ, what those individual bars. So just by doing that, you can then do plt.plot o. And we get a nice partridge. So we have the 0th value here, which is five, then the first value, which is 25, the third value, which is 50. This last value which is 20. So we may want to specify epic more options to make it, but could be pretty. So we can do that in the next one. So we have plt.figure. And again, we're going to specify the barriers that we want. So we're going to use the range function to generate a range of values. That's the, that's the length of our data. And then we're gonna specify our data. Then we're gonna specify the width of the bar chart that we want. So in this case we're going to have 0.7. volume. And then we're going to update the x ticks. So here it may be a bit confusing if you have specific values that you want these x to b. So say you're doing some sales data information on this is demand to have cars that they've sold this month. So you may want to just have the sales persons name. So we can do that using PLT, x ticks. And in the x ticks we need to specify which bear we're updating. So again, we're using the range to calculate or to generate a list of values data as long as the data using the range and then that length theta. And then we can specify the names W12 include in our amplifier. So in this case, we're going to generate a double and it's going to be the sales person's names. So in this case it's Bill. Then we also have Fred and Mary. And we have so so these are the four different sales figures that we're going to be including in this portion. And it needs to match up to these four different bar charts, bar plots. And so we can use plt.plot to show what your 200. And you can see now we have the x label. So Bill has sold five cars this year and we can see that Mary has decided that leader by selling 50. So we can also change the orientation of our burp lush quite easily by using PLT dash H bar, sorry, PLD bar, h, bar h will generate a horizontal barrier blush. So again, we need to specify the range and then the length of the data. Then we can pass our data. And then we can use PLT but chill to show the horizontal bar Bosch. So you can see here, you could update the x sticks by using ERD, sorry, update the y takes in this case, by changing the values to be bill, Fred Marion x2. But this gives you an overview of the options that you can use when creating a bartered. So in the next tutorial, we're gonna be looking at integrating multiple bar charts on some, stacking some pie charts. 23. Multiple Barcharts: We're going to look at having multiple bar charts together in the same figure. So in this case, in the previous tutorial, we thought we were specifying one single value. Dodge was across multiple people. But saying, if you words is selling competition, non jihad, and different types of you've got to care or you had trucks or Yuan heavy machinery. And you wanted to have each of those different options in the one, then you would want to have multiple bar charts and the same plot. So I've generated some data. So in this case, we have a tree arrays with four of authors niche. And we're going to use that to generate our portraits. So I've imported matplotlib and number, and we have our data ready to go. So the only thing you have done is to actually start plotting. So just to start, we're going to generate a range, values. Range for this is just used to help us and plot the values. And we can use PLT, dot, bar and VLT upon x plus 0. And we're going to use the first Dana, that's data 0. And we're gonna set our color equal to b, so blue. And then we're going to set the width equal to 0.25. and so we can duplicate this twice and then we increase the first part of this so we know that the weight is going to be 0.25. So if we increase where we're starting our prior plush by 0.5. dash. We'll line it up to where it should be plotted. Then instead of the 0th points, we want to get the second list of values. So this might be an number of cars sold, the number of trucks, and the number of berries. And we can change the color just to make it a bit more different. The width will stay the same. Then. So the next one is going, so it's 0, 0.25. 0.05. and then we are getting the values. So in the array position two. And then we can change the color to be red and release it with 0.25. And then we can do PLT, show to show what are our chart looks like. Oh, and I should be using a range as opposed to range. So it should be NP and not a range. And you can see here we have our values that have been generated. So you could change the axis labels as well. But this shows you just how you can have multiple bar charts all in the same block. So you just need to make sure that the width is at correctly. On that you're increasing the position of where you're putting the bar chart, but the amount of width each time. So that's how you can have multiple bar charts in the same figure. 24. Stacked Barcharts: Okay, so in this tutorial, we're going to be looking at using stacked bar charts as opposed to using the multiple bar charts. So this is again, if you want to include multiple different values, say you have four sales people. And this is the amount of cars and the amount of pickups, nothing's old. You can use this to create one diagram which is showing you who sold the most amount of cars and vehicles. And it will stack them on top of each other as opposed to showing them next to each other. So if they're all similar value or they got a similar condition for each of them. This could be a good way to give you a quick overview of. Here's the best salesperson. So I've imported matplotlib. We've set up our data, or a and B, and we have x setup to help us generate our plots. And then we can use PLT bugbear. And then we have the x-values to specify each of the individual bar plots. Data is a. And we're going to set the color to be equal to blue. So just specify and be Rican, duplicate that. And then we want to stock and the b values on top of it. So we can set the color to be equal to red. And the way that we stock values on top of each other is by specifying this bottom keyword. And then the bottom gave her two. We're gonna specify a. So this is going to stack our B values on top of our values. And we just need to do PLT that show unto you you can see that the values up and stacked on top of each other. So for the third person here, they sold 45 of a and b. So you can see not q, 095 year. And the first person had sold 5V. So that gives us r n ten. So you can see, this gives us a quick overview of the total amount that was sold in each case. As you did with the original bar chart, you could specify the tick labels and adn legend specifying what each of the colors mean. 25. Boxplot: Tutorial, we're gonna be looking at box plots. So boxplots are a really useful way of looking at the distribution of your data set. And it gives us a good idea of the 2575% quartile and also medium. And some of the outliers as well that we may have in our dataset. So I've imported matplotlib numpy as usual. And then we're going to create our dataset. So our data is going to be equal to np random dots around n. So we're going to generate the random values from a normal distribution. And we're going to generate 105. So we're going to generate five groups of 100 random values from a normal distribution. And so we can use PLT dot boxplot to regenerate our box plot. And we just need to specify the data that we want to pass to it. And then we can use plt.plot O. And so if we run this, we can see that we got the boxplot generated for each of the five sets of 100 random values. And we can see that they're mostly quite similar TO because they're random. We can see that there is slight variation, variations in the median. The 75% quartile, 25% quartile, and then the maximum and minimum values. And also see that there's some outliers in this fourth group on some other outliers here in the fifth group that are almost three standard deviations away from the mean value. And so we can also change the behavior of our box-plot quite easily by specifying a few different options. So if you wanted to change the boxplot to be horizontal, we can do dash, so we do PLT up boxplot. And then we specify the data that we want to plot data. And we can also add a notch to her symbol. So the good thing about pi term is it specifies these options. So if we set that equal to true, we will guess a notch in our box plot. Show. I'll show you what that looks like. And then if we also want to update what our outliers will look like, we can specify that here. So if we do, or as that sounds for a red squares. And we can also turn change M vert, as you see here, to be equal to false. And so that means that our boxplots will not be vertical and the horizontal. And so if you run this, you can see that now our boxplot is horizontal. We have this not showing the median value outliers of this red square to them. And you can see how much it's changed from this initial value. And because the values are randomly generated, so we get some different values in each of the plots. So you can see that they're all quite similar and there's lots of different options that you can explore. It. Boxplots. So if you hover over, you can see all the different positions bush. You can get a pretty code. You're looking bugs Bosh, by sticking to the standard, wish, I'd specifying any options. And if you just want to do this for one, you only need to specify the one list of values. In this case, we've generated five different box plots just to show you how they vary. Bush, Yeah, you can specify any of these additional options and you'll get a good-looking books flush. 26. Piechart: In this tutorial, we're going to look at pie charts. And pie charts are a really useful way of specifying the different percentages of values. And so it creates a nice chart that looks quite like a buy. And you can see how big of a slice is being taken up by different factors. So I've already imported matplotlib as PLT. And now we're going to create our data. So using data. And then we're gonna create our list of datapoints. So 5255020. So these are the values we're going to push in our pie chart. And so if we use PLT dot pi, we can pass in the dataset that we want to block. And then if we just do PLD that show, we can see what we get when we're using the default values. So as you can see here, we've been able to generate a pyplot pie chart. And we can see that the green represents the 5025 is the orange, and then we have the 520. But no one else will really be able to understand what this data means. So it's good to use some of the other options in pie charts to make it a bit more readable if we wanted to appear in a paper or a presentation. So I'm gonna create a list of labels. And the labels are you going to have frogs, are going to have hogs, and we're going to have dogs on logs. So it's got to have rhyming labels. And then we're also going to create the sizes flash our values are going to have in the actual pie chart. So that's going to be 15304510. Then we're going to explode one of the slices of the pie. So it will just mean that it comes out slightly. Creating a nice effect. If you want to specify maybe y one is the largest, start a smallest. It just gives us a slight Tyler. So we specify 0.1000. Then we can create our figure environment. So we have Figure one on to axis one. That's equal to phi sub block. Oh, sorry, that should be PLT plots. And then we can create our axis, our pyplot on axis one by using a x1 dot pi. Then we can't specify the sizes. We then have. So we want to specify the percentages in each of the m bits of the pie chart. So in here we would want to say 50% 25. So we want to create a formatting to do that. So we can do that using auto PC, PCT. This will specify the format that we want to use to show the percent. And so we do present one, dash, one, float, and then percent present. And this should all be in quotations. So this specifies that we only want to have one floating byte number after the decimal point. And then we can say that shadow is equal to true. So this just gives it a bit more style. And the starting angle can be equal to 90. So then we do a X1 dot access, access. And we said that to equal, So equal aspect ratio to make sure that it's a circle. And then we can use plt.plot. We'll run that. And you can see here we have d, I'm percentages being shown on the pie chart. So 45%, 10, 15% percent, and the labels aren't showing up. So let's because I forgot to specify the labeled. So labels are labeled. So if you're in that, you can see now that we have the label of snow, hogs were 30%, dogs were 45%. So we can see that that's matching up now. So when there are things that were missing slightly is the explode. So we need to specify that in her plot so we can sash, explode At equal to explode and add a comma. And so if we run this, we can see now that we've got an exploded view on hogs. So if we wanted to have multiple slides in our presentation and then focus in on hogs. Weekend, exploded on it just shows that we're highlighting in on this one piece. So you can specify a dash, but more by changing it to point to just to join to make it more clear that you're specifying it in a non hogs push, it can be a really good way. Yeah, if you're if you're focusing in on one piece of the pie chart. Yeah, I hope this has been really useful introduction to getting started with basic plots. I've covered a lot of grants so far. So we've gone over into simple scatter plots and density plots, histograms, kernel densities, bar charts, stacked bar charts, boxplots, and pie charts. So in the next section we're gonna go over the customization and configuration. So just specifying a few more options that we can configure to change the axis and the different color options that we have, some style suits that we can use. So stay tuned for that. 27. Anatomy of a Figure: Section we're gonna be looking at the customization and configuration of the figures that we can generation matplotlib. So this first file is called Anatomy of the figure. And I actually want to go through more the figure of producers rather than the actual code. So you can step through it yourself too, is quite a lot. __init__ it's a 133 lines of code. But what's really important is the figured out a producer's. So you can see in the figure, there's lots of different components that we can change and add to our figures. So we have the title of here at the top called the anatomy of a figure. And then have our legend. It's showing the blue signal and red signal. We have our grid which is being generated here and using dotted lines. And we have our axis labels. So we have our x-axis label, which major and minor ticks. And then we have our y-axis label, which has the major and minor ticks. And we also have the blue line signifying the blue signal and the red line signify and write read signal. And we also have all these markers which are scatter plots. So basically, every single thing that you see in a figure is customizable in some way and matplotlib. So we've seen before how we can customize our markers. We can change the color, we can change, and what the markers are. What do we want to stars or dots or lines? And we've also been changing the axis labels. So in the barren charge, we wanted to change it to be the names. And we cannot specify a lot of other formatting options as well. So just running quickly true as some of the code here, we can see that we're doing stuff that we've done before. So we're setting the image on the axis to between 0400, setting the y limit to be 04. So that is the square figure. Then we're specifying the tick parameters. So D minor and major ticks. And we're specifying the distance between them on the label color. So it's using the label color 0.25. So we've seen before that thoughts, the grayscale, which is between 01. We then have our grid, which is being used to generate this grid. And using this two dashes, which gives you this sort of very tight dotted line. We have line went on color. And then we're also starting to generate the plot. So in this case, we're using the x, y, y1 values, which are generated up here. So we have our linearly spaced values. Then the Y1 and Y2 generated using cosine. And we plot those using this O marker that we've seen before. And if we're using the UK market because our edge, which is black, then we can see where you're setting the DIBL, sudden a title, the x label, the y label for it. I'm plotting our legend. And here's where we define the circle. So this is how we draw each of these individual circles. Then for a D minor ticks, we create our circles when you specify where we want to be placed. And we specify the tech, the text, which is the minor tick label. And we do that for all of the other things that we wanted to highlight. So here we have a line on line blush is here. And we also have are legend, which is up in the top right. You can see it's almost foreach where the text is. That's where the legend gets plotted, where it's almost 44. So that's basically how this figure was constructed. But it's really useful to come back to this diagram and figure to define what you want to change. So you might not know that these are called major takes or minor tweaks. And so by going in here, you can see which parameter they're changing. So if they're using t-axis dot tick parameters to change her take parameters. Or if you want to specify the limits, you can set the limit. So set x lim between 04 or 04. So we can be really useful to get an idea of the overall components that go into a figure. So you can return to this later if there's something you want to figure out. 28. Plot Axis: So in this tutorial, we're gonna get started with E plot axis. So I've imported a thoughtless and numpy as np. So we're going to generate our figure environment. Same figure is equal to plt.figure. And then we're going to generate our x values. So we're gonna say x is equal to n p dot linear space. And we're gonna go from 0 to ten. And we want to generate 100 values. So then we can use plt.plot. And we're going to plot the x phi dot sine of x. So this just gives us a really simple sine curve. But we want to add a bit more information now because we're adding some customization dirt. So we can use PLT dot title. This will give the figure title, which is in this case a sine curve. And we can use plt.plot o just to show that. And you see here, and we get our title sine curve, and we have our sign for your being drawn. So if we want to add a bit more properties to the figure, we could also add in the x label and y label. So in this case reduced to PLT thought xlabel. And we're going to call our x label x and our PLT y-label sine x. And if we run this, we see that our axis up enough dated. So we know that here is x from 0 to ten. And for the y values, we are getting the sine of x. So this just adds a bit more clarity to the figure. And show's viewers what we're trying to plot here. 29. Plot Legend: So in this tutorial, we're going to look at using a plot legend to specify what we're drawing in our figure as opposed to labeling ish using a title. So we've imported matplotlib numpy as np. And now we're going to set up our figure environment by saying fig equals plt.figure. And we're also going to specify our axis using AX is equal to pl t axis. Then we can generate our x values. So we're going to use x is equal to NB linear spaced. And we're gonna get, generate values from 0 to ten, and we're gonna get to generate 1 thousand of them. So then we can use plt.plot to her x-values. And we're going to plot the sine of x. And then we're gonna specify the color on market that we're going to use. So in this case we're going to use a dash, so green line. So we're going to specify a hyphen and then green. And we're also going to specify the label. So the label is what will be used in the legend. And we're going to set the label equal to sin x. And so we want to have another plot so we can duplicate this hitting Command D. Then we're gonna change this to cosine. And we're going to have dashed blue line. So we can use colon B, unsettled label equal to cosine of x. So then we can plot the axis, the axis to use equal spacing. And once we have that, we can then add our legend and show what we have plotted so far using PLD adagio. And if we run that, we can see that we have our green line specifying sign and r dash blue line, which is the cosine. And the values are going from 0 to ten, was seen at the bottom. And the values are going from 0 to ten as seen at the bottom. And the result of some other configuration options we can use when regenerating our legend. So at the moment, you have no parameters. It just goes to a free place in the figure where there's no line being drawn. So when try not to plot it over this green or blue line, so it chooses the top right corner by default. If we draw another figure, we can specify some more options in our legend. So we can use at location parameter to specify what location we would like to put it. And we can put it in the upper left corner. And we can also update the frame one parameter, which is frame on, on set that equal to false. And so if you run that two 0s, so we just need money for a frame on and you can see the difference between these two. So in this one, we have a frame around or legend, and it's in the upper right. Here. We're specifying the upper left and we're removing the frame. So we can also specify to have them on the same line if we want to have two columns. So the way that we would do that is by adding the number of columns. So in column equal to two. And we can change the location to be the lower center. And if we run that. So you can see now that we have three different fingers, the sign is at the lower center. There's two columns, so they're all in the same line. Or we can have it in the upper left. Or by using the default positioning, we can just position, position at the top right and have the frame renders. So you can choose a lot of different positioning options which are legend. 30. Multiple Legends: Multiple legends in your flush. In this case, we've imported matplotlib, numpy. We've set up our figure and access environments. We have a list of lines that we are going to use, the Styles. So we have two dash, double dash, dash, dash, and the colon are going to create four different lines. And we're gonna specify the legends into ways. So we said the access to Eagle. And then we're gonna specify the lines and labels of the first legend. And we're going to place it in the upper right with the width no frame around it. So he said frame on to false. So this is very the first two lines. And we're doing that by specifying the AX dot legend function that we'd used before. But another way that you can specify the legend as by doing it manually. So in this case, from matplotlib dot legend, we're importing legend. So it places a legend on the axis, that's the exact location. So you can also specify a number instead of specifying the actual location. So by default it chooses this best performing parameter. But you can also specify another one of these options by using either the number or text. And so in this case, we're creating and letter legend. And I'm putting it on this axis. And we're using the second to last lines, which is line C and line d. And then we're placing it in the lower right location, which a no frame on it. So frame on a set to false. And then we're just adding this axis, this legend that we've generated to the axis. And then we're generating the plush using plt.figure. So if we run this, you can see that we've generated our four different lines. You can see that the OEM interleaved nicely together. So we have line a and line B, which are located in the upper right with no frame around it. So for a mom has been set to false. And then the last two lines, which are line C and line D, is located in the bottom right. And again, we've permuted the flame. So we can either specify the lines manually using this import function on grading or legend, or we can do it automatically using this AX dot legend function. So there's lots of different ways to change the legend when you're creating these sorts of plots. 31. Nonlinear Axis: In this tutorial, we're going to look at using a non-linear axis. So I've imported a numpy and matplotlib as PLD. Then I've created some normal data drawn from a normal distribution. And we're getting the y values greater than 0 and less than one. And then we're sorting them. Then our x values are just a list which is the length of the y-values. So first of all, we're going to create subplots are using PLT subplot. And we're gonna have a one-to-one supply. So one row, two columns on, we're gonna work on the first sublist. Then we're going to use PLT. We're going to plot the x values, the y values. And we're going to set this y scale equals linear. So PLT I scale. And we can specify dash as equal to linear. And we are going to title it. So PLD law Title and Title is linear. So we can also plot the grid using PLT dot grid. So this will just show a grid when we're specifying, when we're drawing our plot. So we can just set that equal to true. And we didn't use PLT touch shown just to show that we've created so far. And you can see we have our linear axis. And these are the sorted random values that we've generated so far. So now we're going to create a, another supply using the non-linear axis. So using a log axis. So we do VLT, that surplus. And we're using 12 seconds. So we're going to use PLT dot plot x and y. So this will all be the same, except we're going to use a different boy scale. So we're going to use a log scale. And we're going to use a log scale here. And the PLD law grid is equals true. So we can run this again. And here we can see the difference. So we have our linear Y scale in this linear plot to the left, and then we have our log scale here on the right. So that's how you can easily change the scale between different subplots and different axes. There is a lot of different options you can use. So you can use a symmetric log by doing SY M log, or you can use logic by using LOGIT. So these just gives you some slightly different access options if you ever need them for some specific task. So that's how you can change to non-linear axis. 32. Stylesheets: But my positive is so good to use is that there's such a large community binders and there's lots of really nice style sheets that are available. So these style sheets specify the colors that you use and a lot of different sizing options make Europe lots can look really pretty. Having to put in almost no effort. And they're really easy to use as well. So all you have to do to specify a style that you want to use is to import matplotlib as PLD as usual. And then you just say PLT lifestyle that you use. And this case we're using seaborne white grid. And so the way you can print all the available styles is by renting PLT plus style available. And so if you come to the bottom here, you can see the output of this. So we have solarized Y2. We have classic dark, bright, grand, fast FiveThirtyEight, GIG, Grayscale, seaborne, seaborne poster, seaborne Postel, seaborne talks you more ticks. And so you'll see that I am, one of the most popular is seaborne. And so 0-1 poster would have slightly larger writing and slightly bigger labels on the axis because you're going to be showing it in a poster environment compared to their paper. So Seaborn paper would have small writing because usually the figures and papers would be much smaller than something that you would be presenting in a poster. So it needs to be extra condensed. So a good way to see all these different style options that you have is by just testing it out on as some sample lots. So in this case we have a function called histone lines. And it just generates a histogram and align blush. And we then just use a lot of different styles. And we have seaborne paper, Seaborn poster, FiveThirtyEight, G, D, P MH dark by Brendan grayscale. So I'll just run this to show you and the effect that the different style options have. So you can see that there's some style options that are quite unique. So this dark background and the grayscale as maybe slightly more boring. Or if you have some need to use greyscale and maybe you could use it, then there's a lot of the veterans that are really clean so they can be used in publications. So this FiveThirtyEight one is quite popular. So FiveThirtyEight is a webpage and they do a lot of prediction based stuff. And they became property or for having these figures. Then there's the C1 booster on the seaborne base paper. So you can see here the numbers and the ticks on the axis are much smaller in the paper compared to the poster. So here you can see that we're much more readily able to see these because in a posterior we want to have and this larger font and spent under for giving a presentation as well. Because if you're usually further back under him compared to a paper where you can get really close to it. And this is at the seaborne white grit as well. So you can see that there's lots of different style options. It will give you great looking blots on the straight away. So it's a personal preference, I would say, to stick with something like seaborne unless you have a very good reason to change. And so if you're going to use the, the dark background, you probably want to have a good reason for this. So maybe your company has a dark background and it would look good on those slides. Bush, most of this standard style sheets are pretty reasonable. So you can use them to get really good looking plot straight away without having to specify any additional options. 33. Text: As using text and annotation and her matplotlib figures. So we've imported not fault them as PLT. I've set up the style to use seaborne like Ridge, and also import numpy as np. So text can be really useful if you want to call attention to maybe a specific point in your figure, or to explain some trend as to why there is a sudden change in your data. So we can set up our figure and axis. X as x is equal to PLT plots. And in this case, we're going to set up a figsize equal to 12 by four. And then we're gonna specify our axis. So we want AX dot access. And we're going to have as 0 to 100 to ten. So this will specify the size of our axis. And then we're going to specify where we want to place our text. So we're gonna do AX dot text. And we're gonna specify the coordinates of 15. Then we can specify what we want our text to say. So in this case we're going to say data column one by five. So one of the important things that we need to specify is the high we're transforming data for our positioning system. So we can use the default which is trans data, which we'll just use the coordinates. So 15, the actual values will be 15 and the actual grid. But if we use trans axis or trans figure, access gets scaled between 01. So we need to specify, say if we want it in the lower left corner, it would be 0.1. 0.01. as opposed to specifying the actual coordinates. And I'll show you that as we go on through the tutorial. So in this case we're just gonna set transform is equal to AX doctrines data on a couple of D for data. And then we can use PLT figures coming along so far. And we need to have things size so we're missing any here. And we can see here that our data has been generated and it's coming up at 0.15. That showing in the plot. So I can show you some of the other configuration options that you can use. If we duplicate this using Command D, we can change the transformation from trans data to trans axis. And we can specify the coordinates as 0.5. 0.1. so you can see this is getting scaled using the axis as opposed to specifying the actual coordinates. So it can be useful if you are changing the axis alone. You want to update automatically by just using a proportion system. So we will change this to be 0.50.1. And we can also specify the heat trans figure transform power working in it. So this is trans. If IG or in this case it's taking not only the access but the entire figure. And we're gonna specify 0.20.2. And we can update our text. You're going to and if we run that and this figure. Oh, and so the mistake that we've made here is that it shouldn't be access because we're specifying a figure. So we should be using fig dot transfigured. So if you run this, you can see that our code is successfully working. We have our point here at 0.2, almost a 22, which is the trans figure. You can see that it's slightly down on the two value because it's having to dig in the white space above and below, which is included in the figure. And for the axis, you can see that it's located at 0.50.1. So you can add text really easy. And the way that you position the text is totally up to you. I think using the transit axis is probably one of the easiest. And though the trends data is the default. So if you know roughly where you want to place your text, this can be quite easy. So if you wanted it somewhere in the middle of the figure, you just specify 0.5. 0.05. and then your text would get moved into here. So you can just update those x-values and run it again. And that will give you some texts right in the middle of your figure. So that's how you can add text here, diagrams, it's quite simple. 34. Arrows and Annotation: Material we're going to look at using arrows and annotations in our plots. So this can be really useful if you have to point to something in the graph and you want to add a bit of text just to explain it. So as usual, I've imported matplotlib, has PLD setup the style to use C19 grid. And we've imported numpy as np. And we've set up prefigure and axis. As tablets. We have our x values and then only space between 020. And we're just going to have a simple goes and part. So I can just use PLT dot show to show you created so far. It's just as important cosign plush. So now we want to add some notations. We can use a x dash notation. And in annotation, we want to specify the text that we're going to use. So we're gonna specify the local maximum and local minimum. And the local maximum, we need to specify the x y point. So this is where our arrow will point to. So in this case we're going to have at 0.26.281. And we need to specify our x-y text. And this is going to be where our text is located. So in this case, our text is 104. And then we can start creating our options for our Arab lots. So in this case, our applets, arrow props. So AIR OR ROW props. So this where we can specify in lots of different options for where, what our arrow would look like. And we specify them as a dictionary. And the first option that we're going to specify is the face color. And we're gonna set that equal to block. And so if we just run this, we can see the annotation that we've created. So here we have our local maximum. The XY text is a 10-4. So it's always ten across then up until four. And you can see that through our text is drawn. Then the arrow that we're pointing to is 6.28 by one. So again, 0.206.28.1 and it points in a straight line. So we're gonna create another annotation and we're going to create a curved line to specify the local minimum. So again, use AX dot. The text that we want is the local minimum. We specify our x y coordinates. So in this case, x y is equal to. And you can use and known by functions as well, where if you want to specify the locations. So we're going to do five pi and pi, one by pi. So this gives you access to you by value. And then our y-coordinate is minus one. We're then going to specify the location of the text, which is x y text. And that is equal to 2x minus six. We can then create our, our props or specified the options that we want in our diagram. Arrow probes and set that equal to the dictionary. And the options that you want to specify are the Aristotle. And we're gonna set that equal to dash greater than symbol and a colon there. And also in our props, we can specify the connection style. So by doing Connection style, this allows us to specify you wanted curved or what sort of connection when you launch in our final annotation. And we're gonna set that equal to angle tree. And we want to specify that angle. So a lowercase a, angle a is equal to 0 and angle P is equal to minus 90. And once we have that, we can run our annotation. Go until I had mistakenly put in an additional bracket here. So if we get rid of that. So the connection style needs to be part of the Arab robes dictionary. And so if you run it again, you can see now that we have our local minimum, the XY text is ash t2 minus six. And we are specifying the location of the arrow to be at five times pi. And then the y-value is at minus one. So there's lots of different options on connection styles that you can use. And so we've gone for, in this case, angled tree than the angle a is at 0 on angle B is equal to minus 90. So this is just the coordinate systems that's used for drawing these lines. I'll just show you some of the options that you have for specifying these different types of diagrams. So this is just a demo of the connection styles. And if we run this, you can see here that we have this angle tree and that's for creating these curved lines. Then we have different arcs and by refractions as well. So there is actually no angles do or Angular one. There's only angle tree. But you can also use these arcs and by our fractions to create whatever type of connection that you want and matplotlib. So take a look at these and they may be useful just to keep for future reference if you want to have a specific connection style. 35. LaTex: So latex is a really useful way of formatting the text to include mathematical operations. And I actually have a full course on latex if you undertake. So you can click on my profile at the bottom of this page. And it will bring up the other courses that I've taught. So NAIDOC is really useful for formatting documents in a really professional way. So it makes sure that the formatting is nicely laid out and equations and algorithms look really nice. And so in this case, I've imported and numpy and matplotlib. We have linearly spaced values between minus 44. And we have this y equation, which is 0.25 times x plus four times x plus one times x minus two. And so what I want to do for this blush is to have a title that specifies the y equation. So we're going to use PLT dot title. And then we're gonna specify the equation using later. Ok. So the way we did that is the first but the gammas, and then we need a dollar sign. And then we have f of x. And we can let that equal to. And then we need to use backslash, backslash to access the fraction Ekman in latex. So the fraction commands, and that's just the light X4 fractions. And so you use the numerator first and then the denominator. So we're going to have a quarter. So we have one and then four, because it's 0.25. and so we have a fraction of one over four. And then we want to fill in the rest of our equation. So now it is x plus four and then x plus one. And finally x minus two. And then to close our latex equation, we need an editor dollar sign. And then we can actually plot our figures. So PLD. And we're going to plot x and y. And then we just need to show what we've done. So I do PLD that Joe. And if we run this, we can see now we have our nicely formatted LE type equation top and the equation is formatted and we have our fraction. So if you take my course, you'll be able to basically come up with any equation that you want to include graphs. And it can be really useful if you're developing specific light takes equations and you want to add some information in the title so it makes sure that your equations are nicely formatted. So you should definitely check it out. If you haven't used before. 36. Shapes: So in this tutorial, we're going to look at how we can use Latex to create shapes. So we have a total blank document at the moment. So we can start by importing matplotlib as PLD and were dying of integration are figure environment. So Vk equal to plt.figure. And then we're gonna create our axis. So we're going to say access is equal to fig. So blush. And it's going to be 111. So there's a number of different shapes. And matplotlib is probably something that you wouldn't associate which and doing shapes like this. But it can be useful if you just want to highlight a specific region of a graph, save trees like a financial crisis in 2 thousand nation and you want to overlay a square box around it. Just I loaded it can be really useful. So the way that we get here we're going to do is buy your pleasure of all draw rectangle. So we say rect is equal to PLT dotted rectangle. And this gives us the options for where you want to and draw a rectangle. So you can see here we have our x y double. And so we're going to specify dash 0.20.75. And then we're gonna specify 0.4. as the width and 0.25. as the height. So PyCharm is really useful when you're getting all these different options just to make sure that you know, quadrotor setting when you're setting all these parameters. So we have our x, y double, then we have our width and our height. And so that's our rectangle. And we're also going to set t alpha equal to 0.3. And we're also going to create a circle. So we're gonna say src is equal to PLT circle. Then we're going to specify the x y point again. So dx by double 0.70.2. And then all we need is our radius, which is 0.25. and I'm missing a point here. So when it's highlighted like that to me means that something's wrong. So I had a comma here instead of a full stop. And we're also going to specify the alpha equals 0.3. And finally, we're going to draw a polygon. So this case we're gonna say begun is equal to PL d dash polygon. And again, we need to specify our x and y. So in this case, it's going to be a list of as 0.25. c. You are going to 15. And it's actually going to be a list of list. So we need to include another square bracket here. And then we're going to have as 0.250.4. And finally, we're going to have another square brackets of 0.20.6. Then we have a square bracket to end. And now we can start actually adding all these plots to the graph. So I'll just specify alpha equal to 0.5 for the polygon. Then we can do a x-dot. And in this case we're going to be adding a patch. So add underscore patch. And we pass in the rectangle. And we can duplicate this and specify it for our other shapes. So our circle under polygon. Then all we need to do is to get PLT slideshow. And if we run this, and so you can see we have our rectangle on our polygon. Our circle is missing. So we've set it to 9.7, but there are limits are one a month. So if we change that to 0.70.2 and run it again. You see now that our circle is here, centered at 0.7 to point to and when a 0.25. radius. So this is redraw the shapes in latex. And see for our polygon, we're able to specify the amount of points that we want. And so it starts at 0.250.15, then goes to 0.30.4 and then up to 0.20.6. So it follows the shape around the polygon and you can add as many points as you want and use the previous parameters that we felt dated. So things like the alpha value. So that's how you draw a different shapes in matplotlib. We can use these to, I suppose you could create a logo or use them to just highlight specific points in your fingers. 37. Matplotlib Unchained: So just one final editorial loans to give you on text and annotations. And it's this map plot lib, Unchained figure. And it's just an animation that's created. So it's on the matplotlib website. So to replenish, you need to change the preferences and pi terms look slightly. So if you go to Tools and then Python scientific, You need to uncheck, Show plots in the two window. So all of the plots we've done so far that appeared in this plot window on the right. Both for animations. It does mark in by term for some reason. So maybe we'll update that soon. But for the moment, M animations don't work, so you need to uncheck that. And then if you run this, you see you get this map plot lib Unchained. So sort of like a causing Joy Division type. And so it was an album cover for a Joy Division which shows a band. And you can see we get all these different sort of sine waves that are going through the figure. So it's just a really cool sort of animations that you can do this using matplotlib. This is all the code that's used to generate it. So we have, It's quite well laid out where we generate the line plots. And they are quite simple, so they're just access line plots that we would have used before, where it's setting the x limit on the y limit and then adding the text or the matplotlib Unchained. And then we just have an update function. So this just tells us the, the animation how to update. And then it just recursively draws itself. So I don't go into animation in this course, but it's something that you may want to look into if you're interested in doing it for future work. We will go into some interactive plots later in the course. So this allows you to interact with some of the plots in an actual web browser. But it's just something to be aware where of. And it's a pretty cool simulation. And if you want to maybe try something like this in future. 38. Basic Errorbars: So in this section we're going to look at plotting basic error bars in continuous and in symbol functions. So it can be really good to push era virus in your function, especially if it's going to be a published article. So usually want to include some confidence interval as opposed to just the mean value, which can be quite misleading. So a lot of different journals and conferences will look for you to have these error bars and your plot. So this is how you plot them in my public. So the first thing that we're gonna do is import matplotlib as PLT. And we also want to import numpy as np. And we're all set of styles, appeal t plot style. And we're going to use t born white grid. Okay, so now we have everything important that we need. We can create our values. So we are going to use an entity space, so NumPy linspace. And we're gonna go from 0 to ten. And we're going to create 50 values. Then we're gonna specify the era that we're going to use. So in this case, it will be DY and we're just going to set it to a constant value of 0.8. Then our actual y-values, they're going to be equal to pi sine of x plus pi times some random value. So run them around. And we're going to generate 50 of those 50 values. Then we can use fealty dot error bar. And this gives us access to all the parameters that we need for creating our error bar. So we have x and y value that we're going to use. Then we specify our wire. And that's going to be equal to DY, which in this case is the constant value of 0.8. And then we're going to specify some format options. So we're going to have dash, okay, so the small circles or the block. And then we're just going to PLT that, show this. So if you're in this, you can see here we have our errors. We have the small circular values. So this is giving us m, d different errors that are located around these as opposed to just mean values. So we can also specify some other additional parameters in our error bars. So by using PLT dot error, dodge error variance, again, we specify x, y, r wire is equal to d y. In this case, our format is going to be equal to the bigger circles. So lower-case o. And we're going to sash color block. And our error color equal to light grey. And we can also specify D airline width. So E line width is equal to three. I cup size of 0. So now we can PLT that, show this at all. And if you can see now, we've gosh, so they're plotting the exact same values. But in this case, we've changed the error width to be slightly wider. Our points are bigger circles and we're using this light gray color. So I think it's probably better to have a light gray color to show the deviation in your errors on where the actual mean values lie. But it's very important to include error bars, especially for published articles. So make sure you're including them the next time you're creating a diagram. In the next tutorial, we'll go through how to use them for a continuous bots. 39. Continuous Error: So in the previous tutorial, we looked at the error bars and setting the different parameters. So setting the color of the error and also the points in the actual figure. In this tutorial, we're going to look at the continuous errors. So I've imported matplotlib numpy. And I'm also using a Gaussian process regressor from SKLearn. So make sure you have the SKLearn package installed. Then we just define the model and draw some data. So we define the model and using this lambda function. And it's x times sine x and R x data is just this array here. Then our y data is a model of that x data. Then we create our Gaussian process fish. We fish the model to our data. And then we create our X fish of linearly spaced values between 0 and n. And then we're making predictions for this X fish and returning the standard deviation. So we then create the D, which is the 95% confidence interval, interval. So we're going to times the square root of the standard deviation to give us the 95% confidence region. And so to actually draw this, we can first of all do plt.plot. And in here, we just wanted to blush the x data and y data. And we can also specify some options. So in this case we're going to do circles and we want them to be red. So we specify OR We can then plush our fish. So it's PLT dot plot. So this is the fish of the function has been created. So we have X fish and Wi-Fi. In this case, we're just going to have a line. So we specify a dash. And we want the color to be gray. So we just say color is equal to gray. And finally, we want to plot her confidence intervals. So to do that, we're going to use the PLT fill between. So this will creation like am bounding box or underline that shows where the confidence interval is. And so our points are the X fish, fish, X fish, and then the whitefish minus the Dui fish, which is the error. So Dui fish. And then the wife et plus the d y fish. And finally, we can specify some formatting options. So in this case, we're gonna say that the color is equal to gray as well. And we want to change the alpha value to make it a bit translucent so that you can see the actual body binder sort of in the same way that you can see the gray bind this value. So we set the alpha value equal to 0.2. We're then just going to earn any limit to our x-axis. So x and M from 0-10, as that's where we use a specified are linear space from 0 to ten. And then we can just do PLT that show. So if we run that, you see that we get this continuous error bar and the fill between as filled between these areas. So the actual date data is these red circles. So this is the actual data. This is the model that was plotted to us using the Gaussian processor. Regressor is the actual line here. So you can see it captures each of the points quite well. And then the 95% confidence region is this shaded area here. So you can see in this point where the line is quite an straight and smooth, there's quite a low confidence or the D confidence region. 95% confidence region doesn't take up too much space. But say here where there's quite a large change, you can see that the confidence region increases quite a bit between the two points. So you can see that the confidence region at the actual points reduces to almost 0 because it knows that these points are part of the model. And so that's how you create a continuous confidence region for plot. And you should definitely do this if you're working in any scientific documents or something that you want to get published because it's often something that reviewers will point out, is that they want to out confidence intervals in the actual plots to give them a better idea rather than just using the average values. 40. Hexbin: So in this section we're gonna take a look at grazing some interactive plots. And to do that, we're going to use the boca visualization library. So this is a library that allows you to create these interactive visualizations. And they have a Kisho page as well. So it's at Boca. Boca. And it allows you to create these interactive data visualization plots in the browser using Python. So I just want to show you some quick examples of how you can use this. And we're going to first of all, look at a hexbin example, which was something that we'd used before in matplotlib. So this section, we're just gonna go through hexbin colors and an example blush one limb is to show you some of the other visualization options that are available apart from matplotlib and bokeh is designed to be more used in browser. Whereas where you can like sort of interact with the plots. And matplotlib would say me for more static figures that you would include in presentations, posters, and comfort articles. So first of all, we can import numpy as np. And you need to make sure that you have bocce installed before you do this. So make sure that you've either pip install dish are used Anaconda to install all of the requirements of this course before you do this tutorial. So from Boca, Joe, we're going to import, I put file and show from Boca that models. We are going to import hover tool. So we need capital H, capital D. And finally from Boca plotting, we are going to import figure. So first of all, if we're going to create our data, we're going to specify n equal to 500 for 500 data points. Then we're going to specify our x values. You're going to be equal to two plus two by nine by random, standard random. And then we're going to use standard normal. And we're gonna create n values. And then we can duplicate that. And we're gonna do the exact same thing for our y-values. So then we're gonna create p, which is going to be our actual plush. And we're going to let that equal to a figure. In the figure, we're going to set the title. First of all. So we're going to set the title equal to exp in four or 500 points. And then we want to match the aspect. So much underscore aspect and set that equal to true. And we want to add some tools as well so we can specify the tools Equal to the wheels him. And we need to have these in quotations. So tools, we'll underscore zoom and a recession. We're also going to include background fill color. And we're going to specify that a x value of four for as 054. And finally, where you're going to set the p dot grid. No visible to me equal to false. So in the next part, we need to create the bins dot we're going to use. So we specify or bins. And we're setting that equal to P dot hexbin. And here we're going to be using our X and Y values. So we specify x and y. The size is equal to 0.5. the hover color. We can specify as well by doing over underscore color and setting that equal to pink. And then we also want to update the over alpha to be equal to 0. So finally, we want to create a circuit as well. So you have P naught circle. And we're gonna specify lash out at x, y. I'm gonna set the color equal to wash, the size equal to one. So you can see that the formatting options are quite similar to what we've been using in matplotlib so far. And by specifying the color and the size and all the different attribute values. So you'll see that a lot of the more recent formatting libraries that are built on matplotlib have quite some NOR interfaces. And so now we're just going to present some tools. So P dot tools. And we want to add a hover tool. And we need to specify the tooltips that we want. So. Tooltips. Now it's going to be equal to a list which contains the count. So in quotations, the count. Then we want to specify at C, which will give us access to the actual k2 values. And then within the same list we want to and q or to give us access to the bins and add the d r value from the bend. So we specify in quotations, the queue, or we alternate specify at Q to get access to the actual values. So at Q and R, And we close ash quotation, close the bracket. And we specify the mode that we want to use. And in this case it's going to be most. So it's going to be most E comma there. So the mode is going to be most are appoint policy is going to be following us. So point underscore policy is equal to mice. Follow this. And you renders our is equal to. And so now we've finally created her. We finally are just all the components that we need to create our interactive blush. And so we can create an output file. And that's going to be just equal to n quotations. So dot-dot, slash and hexbin. So put hexbin dot HTML in the current directory. And then we're going to show our interactive block by doing show P. So if you run this, you can see now we have our interactive block and we're able to hover over the components and see the value and the Q or valleys. So we can also zoom in on a specific region by using the willingness. And we also included reset. So we can reset our diagram to the original values. And we can see that it's updating when all these different kinds. So this is a really simple way that you can create a nice page on a web page that provides some interactive data visualizations. So in the next few tutorials, I'm going to give a quick overview of some of the other interactive plots that you can use that you can create using Boca. So stay tuned for that. 41. Colours: So this next tutorial is looking a hex color picker. So it's actually a really useful tool for breaking some of the colors that we've been working with. If you want to specify the hex value, it's a bush more intensive to rate this. So I'm just going to give a quick overview there. So we're importing the color system from Python and then from Boca, we're importing the layouts model, plotting on teams. And we have a function to convert RGB to x from x two decimal. So basically, what all this code does is it creates a slider and then shows the x value of the RGB colors. And so you can use it as a color picker. So it's actually a really useful do. So if we run it, it will compile and then load up the color picker. So you can see that the hex value for y is fff, fff. And so you can hover over all of these different colors. So say if you want to create a nice green color, you can hover over and see what the x value is and then update in your actual plot. You can also use these sliders. So you can see that the biker and changes to update the sliders. So if you want to have a nice purple color, you can use these RGB values or just copy this x-value. So A36 CFF. And you can use that to choose what sort of x values you want to have in your matplotlib plots or for using as little debugger plots. So it's a really useful tool that you can grayish. And yeah, if you put it on a website and I'm sure some of your people that go through it and find it very useful to use. So, yeah, you can just buy around British and come up with some nice colors that you can use for future plots. 42. Les Mis: So the final interactive plot that I'm going to look at is a plot of the character interactions in the MS. So the MS was a really famous novel by Victor Hugo. And then it was turned into a musical. And it's been really popular as a musical as well. And so we begin by importing numpy as np. Then we installed as starfish importing from, got to finish our interactive plot visualizations. Then actually, quite luckily Boca as a sample data library on one of the datasets started includes Islam is. So you can see there's some information for here. So it's 1.6 kilobytes and it provides the co-occurrences of characters for amaze. And so this can be a really useful way of finding azure a lot of information about the character development and a story. So I think using machine learning can be quite interesting. Or you can just send visualization to find out which characters are interacting. The most unheated dash sort of leads to different storylines developing, tried to book. So in this, we're using a 2D histogram to find out the interactions between each of the plots. So I'm not gonna go through the code in much detail because it's quite simple. So it's just when the different characters are interacting with each other. And then we create a over a tooltip to Actually C1 the amount of occurrences of one day interact via Twitter. So if we run this, you can see this is what is generated. So we got this 2D graph, which indicates all of the times dot the different characters interact with each other. So maybe in this recording, it can be quite hard to see the names. So we first of all, we have child to child one. And then you can see how the main characters such as volume, he interacts with lots of people, try to storyline because he's the main character. So we can see here that he has a lot of interactions with these different people. So the judge, he has interactions to write the storyline. And we can also see here how these group of people have close interactions with each other. Because there's a lot of interactions in these different sets. So you can see that there's sort of clusters of interactions where these group of people interact with each other. These group of people interact with each other, hadn't these groups, and these groups, group and through just seemed to be a lot of em, inter cluster relationships. Although there are a few, but they're mainly true, val John, which is the main character. So maybe that tells you something about the storyline, even if you've never read it before. And it wouldn't recommend your reading history or at least seeing the musical or the movie as they're both quite good. So this is a, an ultra Xunzi, the count of the amount of interactions. So between causation by John, we have Tertullian interactions, which is very high compared to all these other ones. So, yeah, this is a very useful way of getting an insight into what the story was about and the characters interacting with each other by using Boca and grading this interactive visualization. So in the tooltip, we see the names and also the kind of interactions. 43. 3D Points and Lines: Action. We're going to look at working with treaty figures in matplotlib. So I would advise at use caution when using 3D figures and to only use them if necessary. So avoid using 3D bar charts where there isn't really a need for three-dimensional, utterly takes away the emphasis of the data. But sometimes when we're working with data that's entry and mountains and as an x, y, and z axis, we need to use a tree dimensions. So MATLAB limb is actually quite good at doing this. So we're going to look at the ASH In this section. We're going to look at some points and lines, the contour plots on some surface plots. So as usual, I've imported number on imported matplotlib as PLT. And we're going to set up our axis. And we're going to use PLT dot axis. And we're going to set the projection equal to treaty. That needs me in quotations. So projection equal to treaty. And now we can start generating our data that we're going to use for our treaty plush. So we're going to have a Z line that's going to be equal to NP linear space. And it's going to be from 0 to 15, and we are going to have 100 points. We're then gonna create or x line. And that's going to be equal to n, be a sign of the z line. And we're going to duplicate that and say that our wireline. So y nine is equal to numb by dock at the sign of the deadline. So x line. And we're going to the wireline actually equal to pi dot cosine of these headline. So we can create a treaty scatterplot of the data by using AX dotplot treaty. And to create this, we need our x line are wireline on then our Z line. And we can also specify all of the standard formatting options that we've used before. So we want to set the color equal to gray. And so if we plot just this two, so show what we've created so far using plt.plot. We can run that. And you see here we have our curved line, which is going in three-dimensional space. And it's a treaty of the x, one line, line on a line. And it's this grey colored line here. We're going to add a bit more detail to the plush. So we're going to add a number of points. So we're gonna save that. I'll add a z data is equal to 15 times nine by random. And then we're going to use the random function to generate 100 random values. Then we're gonna say that our x data is equal to n dot sine of d z dot plus 0.1 times the number by random dot rand n 100. So we're generating and that are 100 random values. And we can duplicate that and use it for our y, Dana is equal to the cosine does end data. And we're also multiplying it by 100 random values. And then we're going to generate a scatterplot using AX dot scatter in this case. So it's a 3D scanner blood, so scattering treaty. Then we specify our x arrow y data and r z theta. And we're going to set the color equal to d z. And we're going to use the color map of greens. So if we run that again, you can see now we have d's. So the original plot, the treaty plot, which went like this. And now we have the x data, why data on Zen data, which has some random values around it. So you can see that it follows the curve, curve with some error and follows all the way up through a tree dimensions. So this is how we can create Laplacian treaty. And this green color scale. You can see how it changes as d z data increases. So as it gets further and further, colormap goes darker and darker. So it's very bright here, and then gets darker as the color goes up. 44. 3D Contour Plots: To create a tree door 3D contour plot, which sort of like the density plots that we were doing AND getting started with basic Plots section. Except now it's going to be an actual three-dimensional figure. So I've imported num by as MB. I have imported positive as PLT. And now we have our function f of x and y, which creates the z values. So we're going to specify the x values that we're going to use to create our plot. So it's going to be x equal to num by linear space. And that's going to be from minus 66. And we're going to turn the values. So we're going to duplicate that. And we're gonna specify our y values, which are equal to linearly spaced values between minus 66. And again, we're going to have 30 values. So now we're going to create a mesh grid. So we're going to have capital X and capital Y is equal to Numpy, the unmeasured. And we're going to use our X and Y, X and Y values as part of our mesh grid. And then we're going to specify that our z values, r equal to r d returns from our function. Using the x and y values are going to pass the X and Y into the function f, And that will give us our z values. So now we can start plugging these values that we've created. And so if we do a fig plt.figure, we can then create our access as well by saying excess is equal to PLT axis. And we need to set our projection equal to treaty again. And then we can start creating our contour blush. So we do AX dot contour. And in this case it's a tree D counterpart plots. So we need contour tree D. And then we pass in the values that we need. So we need x, y, z, in this case, the amount of levels. So we remember that from the density plot where we need specify on many levels is going to be in the actual plot. And then we can choose the color maps. So in this case we're going to have a map equal to binary. And finally, we're just going to set the labels. So x dot x label. And we can pass that x. And then we can duplicate that and set the y labels equal to y and the z label z. And finally, we can just use PLT that she'll see what we plotted. And so this needs to be a lowercase d fret 3D. And so here's our contour plot. So you can see this is the function that's been created in 3D. And we can also change the column up to the greens instead of binary. And this gives us a nice green color. And we can see how the function changes in 3D, where it gets higher near the 0 values. And then also has this cone at the end, which also getting higher in the more extreme values. So you can see it's quite a complicated function on this contour plot gives us a good idea of where the high and low values are and is perhaps more intuitive than the density plots that we used before. 45. 3D Surface Plots: We're gonna go over using a 3D surface plot as opposed to a contour plot. So in the previous tutorial, we created a function which is the exact same as this. So it was squared and y squared, taking the square root of that and then putting it into a sine value. And this gave us this equation or this plot that we have here. And the values were linearity space from minus 66. And then we created this mesh grid. So using the contour plot, we are able to create this contour plot. And you can see all of the counters going in circles. But say if we wanted to just create the surface instead of a contour plot. So then we could use a actual plot surface function. And that's what we're going to creation this tutorial. So I've set up the function and created all the data points. So all we need to do now is to setup our finger environment and start plotting. So you do figure equal to PLD figure. And then our axis is equal to plt.plot axis. And we want to set our projection equal to D again. And then we can start our plot surface. So we do a, a x dot surface. And then we specify the values that we want to plot, which is x, y, and z. We can specify our stride, so d is equal to one. The stride is equal to one. And then we choose the color map that we want to use. This we're gonna choose c naught equal to V i or i, d s. We're going to set our edge color equal to none. Finally, then we're just going to set our title equal to surface. So AX dot subtitle and set that equal to the surface. So then we can shore up lush using PLT VLT that Joe. And if we run this, you can see now that we have got a surface plot as opposed to the contour plot, that just gives us a better or sort of a different view on the contour plot by showing us the actual surface. So these are both really good ways of creating these 3D visualizations on they can be really good for graphing more complicated functions that are in treaty. 46. Tube Stations: So in this section I want to give you some guidance on how to plot geographical maps. And one of the best packages of entity that is CARTO p. So it's a Python package design of her geospacial data and processing in order to produce maps and other geo-spatial data analysis. So you can use matplotlib to create some, a basic geographical plots, but it's better to use a specialized package like this, as it gives you access to much more different formatting options. And also has a lot of inbound inbuilt maps and different boundaries and projections that you can use as well. So I went to advise you to use something like this. And you can see they have lots of different examples in their gallery. So if you're looking to do some geographical plotting, you should use something like this. So in this section, I'm going to go through a tree, really quick tutorials, just give you a basic overview of how it works. So in this case, we're plotting and the geographical locations of the tube stations. So we first of all import matplotlib, numpy, then we're importing CARTO B. So make sure you have the package installed. And we're importing the image tiles and importing OS m. So then we create our tube locations. And so this is available online. So we want to just create a plot of where all the tube locations are in London and you can get this data available online. We then create our main function, very setting up our finger environment and adding a subplot in the circles that were going to be the tube locations on then just drawing the tube locations using the functions that we get access to from CARTO p. So if we run this, you can see here we get the image of the lunder London Underground locations. We're using the London Underground sort of icon here, and we're also getting access to the underground station names. So here you can see common garden, Leicester Square, Piccadilly, Circus, St. James's Park, Westminster. So these are all the underground locations in this picture. Here's where we're setting up the underground location marker with the red circles on the blue rectangle. So here is our bread consecutive concentric circle that we're creating using the access dotplot. We're also specifying the rectangle using the same technique as well. So that's a 3D symbols to plot these things using Toby because they take care of a lot of the projection issues. And you just have to specify the actual locations that you want to plot. 47. Nightshade: So in this tutorial, we're going to look at using the nightshade costs in CARTO P. And this gives us access to wash. Part of the world is currently brush on. One part of the world is currently dark. And we can do it for any period of time or any specific daytime. So I've imported daytime, matplotlib and Toby. And we've created our finger environment and we've added a sublist using this CRS package, which stands for the coordinate reference system and the transformations between them. And this gives us access to a lot of the transformations that we need when creating global projections. And we're setting the Daesh as the 12th, the 21st, December 1999. And we're gonna see what period of the world was bright and dark during this time. So we have all the data that we need so that we can set up our axis as AX dot subtitle. And we're gonna set the title to be equal to night time shading for and we're going to add in the date. And then we're going to add the stock image, which comes from character Toby. And it's just an empty image of the world in its default configuration stock image. And then we're going to add a feature to the axis, so AX and feature. And in here we're going to add our nitrate data. So we create an instance of nightshade and here telling us to specify the datetime. So we have our data stored in Dave, and I'm going to set the alpha value equal to 0.2. So now we can show what we've plotted using plt.plot o. And if we run this, we can see that we're able to identify that most of Europe and Africa and South America was in brightness and the rest of the world was in darkness for her this specific period. So we're using this nightshade variables to specify for the 12th of December in 1999, I share at 12 noon, this part of the world was in brightness and Australia was in darkness. And so South America and Africa and most of Europe was in brightness, and Australia was in darkness. And we can change that to be m for any different periods. So if we want to change that to be 20. And again, you can see now that a lot of Europe is in darkness and Africa has in darkness. So depending on the time of day, we can see that the nitrate will update to see which part of the world was eater in brighter darkness. So this can be really useful if you want to display this information in a figure, a graph. 48. Global Map: So using a standard library, like Bartleby gives us access to a lot of different projections that we may need. So using looking closer, this coordinate reference system module, we can see that we get access to the Robinson projection, which is a Pseudo Cylindrical and compromises that is neither equal area nor conformal. So if you want to draw a point between two specific places in a map, you need to make sure that you're using the correct transformation. So in this case, and the transform is placed carry. And so you can read up and get a bit more information about it. So please carry, so it's an equilibrium tangled production. I'm saying that the world is made up of these equally rectangle projections. And so if we, this, you can see that it gives us quite a straight line. So it takes me a while to plot, but you can see between the two points that we're plotting. So minus 0.8245458720000 receiver yet at this quite straight line. But if we want to use a didactic protection. And so if we look at a geographic coordinate system, this is using a slightly more Treaty and graphic protection system using Boeing's formula. And so if we run this, you can see that this is giving us a more 3D projection, which is taking into account the curvature of the earth. So just take this into consideration and make sure that you're using the correct transform when you're drawing between two points on a map. 49. Plotting Images: Let's see how matplotlib can be used to work with images. So to begin with, we're going to start by just plotting some simple images. Then we're gonna see how we can use some of the functions to blur the images and also to do some analysis and to crop some of the images automatically. So to begin, we're going to start as usual by importing matplotlib, PY plush, PLD. And we're also going to import matplotlib image as m, p, m, g. And we're also going to import numpy as np and are going to from PIL. So the button image library, we're going to import image. So make sure you have all the required modules and loaded and installed so that you can use these functions and this section of the course. So we're going to import image from there. So we're going to define our image and set it equal to MP ING dash, I am read. And then we can just read in our file, which in this case is parrots JPEG. So we can print our image just to see what the values that we're getting. So this will just print the RGB values. So you can see here at the bottom of the screen, we have a array of arrays, and they just tell the individual values at each point in our actual image. So we can double-click in the image here. So it's just an image of two parents and a sort of blurred background. And so this is the actual values that are representing the colors in this image. So the RGB values. And so we can do some analysis and see you've washed different characteristics of the image areas such as the luminance. So if we wanted to plot the image, we can do Ay mg PLT and set that equal to PLT, IMHO. And we can show then are IMG's. So that's we've loaded in our image and then we can just use plt.plot o. And if we run that, you can see now we have our standard matplotlib axis and this is showing the parent image. So we can also do some analysis like adding the luminance values. So if we do luminance image, we can set that equal to IMG and then we can get access to the luminance values by using the colon, colon and 0. And then we can do PLT dot image shell. And we wanted to show luminance image. So if we make another column to plt.plot show, to show this nourish. You can see now we get the luminance values as well as the original image here, where we have just the RGB values. So we can also specify a number of different color maps. So if we do PLT image show, we can show the luminance image and specify the colormap equal to hot. And again, if we do PLT that Joe, we can see how that looks in our image. So you can see here we are getting the different color scheme as opposed to the screen. We are getting this read of where the luminance values are high. So if we want to include a polymer, we can do that as well, like we've done in some of the density plots before. So you can do image harsh and then PLT Bosh colorbar. So this a really good approach. And matplotlib is that a lot of these options are consistent, threat the different figures. So it doesn't matter if you're working with an image or just a regular Matplotlib graph, you can also include a polymer. So if you run this, you can see now we know what the level of these values are. So the white values are in 250 and then the dark values around 0. And we can get an idea of what the red values are in theater. And so there's lots of different colormap schemes that we can use. Another popular one in images is the nymphs spectral. So I'll just show you what that looks like. So we copy this and change the color map to NumPy spectral. So n p underscore spectral. And if we run that, you can see here we get this spectral color map where the red values are now equal to 250. These sorta purpley values are equal to 0 and the green values are around 150. So it's providing the same information as this. It's just displaying it in a different format. So you can see the information is the same. It's just the colormap scheme that we're using is a bit different. So that's how you can use an pie to display images and different luminances. 50. Blurring Images: To do some basic image processing on our images. So I've imported all the standard libraries, again, imported matplotlib as PLT, imported matplotlib dot image as MPI IMG, and NumPy PIL as well. So now we're going to create our image or loading or image using MPI, pi and G imagery. And we're going to read in from parts dot shaping. Okay, so once we have our image loaded in recount, show us using plt.plot H0. And we're going to be showing the image. And then we can just do PLD that show. And so this is just the standard image wish, no blurring being editor. And so you can see here, it's what we expected. But to do some interpolation or to add some learning, we can do PLT, IMHO. And then we're showing the image. So IMG, then we're setting our interpolation equal to nearest. And then we can do PLT dot show to show what effect this has on the image. And so you might not be able to pick it up as clear in the recording, but you can see that there's been a change in the interpolation and that this image is slightly more blurred. So one way it might make it a bit more clear is by using the bi cubic interpolation, which is, makes it a bit more obvious. So if we change the interpolation to be bi cubic and run that, you can see that there's now quite a big difference between these images. So if I just close all these images and run it again. So we have our original image here, and then we have the image using the nearest neighbor interpolation. And then we have the image using the bi cubic interpolation. So you can see it's become a lot more blurred in this image as compared to the original image that we had. So it might not come at that dwell in screen recording, but you should be able to see if when you're running it locally on your laptop or computer. So this is how we can use a plot lib to some basic image processing on figures. 51. Circle Clip: This tutorial, we're going to use matplotlib to create a circle clip of an image. And this is just to create a circle or in the face of an image. So that could be used in like a LinkedIn profile or something. And so what we're going to do is to, first of all, import matplotlib has always dash BY plush as PLD. And then we're going to import matplotlib dot patches as patches. And we're also going to import matplotlib cookbook. So see book as C book. So then we're going to use R to create our image file. So in this case, our image file is going to be equal to the cookbook Seabrook. Sample data. On the sample data that we're going to use is the grace underscore hopper PNG file. So Grace Hopper was a really famous computer science person and she had worked for nasa on the space rockets and the lunar landing. So we're going to creation or image and set it equal to the PLT image read of the image file. And so once we adopt Rican show are imaged, so PLT image o. And then we can use PLT dot show to show it in the actual and PyCharm. And so image show is missing the actual image that we want to show. So we fill in image here and run it again. And so this is the image of Grace Hopper. And so what we want to do is to create a circular interface. So this could be something maybe that you, if you had a lot of these images that you may want to automation using Python. So we just want to create a circle or in this face here. So the way that we're going to do that is by setting up our figure on axis as usual figure and x is equal to PL d dot subplots. Oops. And then image is equal to AX dot image of the image. And then the patch is equal two patches dot circle. The circle is going to be centered on 262, which should give us a good centering for the face. So the x-value over n 2.6D and then live on your end. 200 is pretty much centered on our face. And we're going to set the radius equal to two. We're going to use the transform of x dot trans data. So this is making sure that we're using the rail points rather than like a proportion of the figure as we seen when we were doing our text. So transform is equal to AX dot data. And then we set our image, such clip art to patch. And so we're going to specify that our axis is off. So x-dot axis, and then pass it off. And then we can use PLT nutshell. And so now we've created this image where we have the face and we've clipped or end a circular image. So you can use this for like a LinkedIn profile. Or if you were doing some formatting on your website, that gee could automatically format these images to be circular and to have the background to me wash or transparent. So this is just a few of the different ways that you can update images using matplotlib. So take that into consideration and if you want to it quickly and you need to format a huge amount of images. So say you had 10 thousand images. It can be a great way to do some initial processing on them by just using some simple math authored functions. 52. Ancombe's Quadrant: In this section we're going to look at seaborne. So C1 is a library that is built on top of matplotlib, and it provides a more high level interface for drawing figures such as this. So the way that we can install it and it's quite temple. So it's the same as installing all the odor module do interviews for this course. So if you're using Pip, just do pip install seaborne. Or if you're using Anaconda, you can just do Conda install C1. So you would abstain and our stylesheets before and matplotlib, we can actually import the seaborne stylesheets. And that's just one of the features that we gosh, what Timor. And so it's just a more high level interface that is actually built on top of my positive. And it makes it slightly easier to do some of the blood's. So in this section, we're just gonna take a quick look at some of the example plots that we can use with seaborne. And the first thing that we're going to do is to plot this Anscombe's quadrant. So it's four datasets that have nearly identical descriptive statistics. Yet a very different distributions appeared very different when craft. So each dataset consists of 11 X Y points. And you can see this is the figure that we're going to try and block. So you can see that the regression is quite similar for all of them, even though they have very different outlines and the points are space quite differently. Okay, so now we're going to jump into pi term. And so the first thing that we're going to do is import seaborn as SNS. And then we're going to import matplotlib as matplotlib, wi blush as PLT. And then we're going to set the style for our graph using SNS dot sash, and are going to set the style equal to tics. We're then going to load the dataset for Anscombe's quadrant. So luckily this is included in C1. So we can load, we're going to store it in a DataFrame. This is going to be SNS dot load dataset. And we're going to load dish which Anscombe? Anscombe. So now we're gonna get started in plotting our actual dataset using seaborne. So we're going to use an S and S dash LM push. So this plot that shows linear regressions. And you can see the first thing we want to have in our dataset is our X and Y values. So we're gonna say x equal to this case x. And then y is equal to y. And r column is going to equal dataset. And we're gonna put the hue equal to dataset as well. So the data that we're going to flush is stored in our DataFrame. So data is equal to df. And then we're going to wrap our columns. So if we want to have the same as we've seen in the Wikipedia article. So we're going to have two columns by two rows. So we can sash the ment of columns on the collar up. And we can set that equal to two. And we're gonna set our confidence interval to be equal to none. So we will just plot that for a moment and see what it looks like. So plt.plot, Oh, you can run this. And so you can see we've got this quite nice looking figure. And it's very straightforward to use seaborne. So we've just supply dish with the x and y column names. We've loaded in our dataset from this dataframe. And we've specified the confidence interval. So if you wanted to add a confidence interval of 95%, we can do that and run. And now you see we get a confidence interval for our regression models. So this is what we'd expect, where the confidence interval is closer in the middle for this diagram. And then it's, the confidence interval is bit shorter here because that's where all the points are. And there's less points nearest were a confidence interval grows because it's less sure of where the regression model should be. So we can also change the polish on some of the height options. It's really easy to make these changes in am, seaborne because all of these options are available straight away. So we can change our polish to be muted. And we want to change the height equal to four. So if we rerun that, you can say, you know, dash d ticks on legends of increased in hi, andar polish has changed slightly to be muted. So if you want to learn more of the parameters that we've concession in this blush, using a laptop, you can just hover over it. You see all the different options that we can specify. So we can specify robust, we cannot in lots of different competence intervals. If we hold command and click on it, it brings us to the function definition. So you can see we have a column order, row order x bins. So you can customize this as much as you want. But one of the good things about T1 is the default options are really quite good. 53. Scatter Plot: Look at C1 and we're going to take a closer look in this case as the scatterplot. And we're going to be using a scatter plot to see which of the features of a diamond leads to the price increase. So first of all, we're going to import seaborn as SNS a0 b1 unrolled to import matplotlib dot p as PLT. We're then going to set our style using SNS. And we're going to pass in the style equal to white grid. So we, once we have our module is imported, we can load our example diamond dataset. So luckily enough, c1 comes with a lot of pre-populated datasets. So we can just say diamonds is equal to S and S dash load dataset. And the dataset that we want to load as diamonds. And we can just take a quick look at what the main features are in this dataset by printing diamonds. And if we run this, you can see printed at the bottom, we get a good idea to features. So we have 53,940 rows by ten columns. And the first column is the carriage damming of the cut. So integrate ideal premium, good. We also have the color and the clarity, the Dept, the table on the price. So I actually know very little about diamonds. The only one that I really recognize is the courage. I think the bigger it is, the more expensive it will be. So we can see these features when we vote in the actual dataset. So if you want to learn a bit more about diamonds, there's a good Wikipedia article that goes through the different features such as d time and clarity and the various grading schemes that they have to rank diamonds. And we're gonna be using this in our actual plot. So we'll include the different grading schemes and see how that affects the price. So now we're going to set up the air figure and our axis using plt.plot. So blots. And in this case we're going to specify that our fig size is equal to 6.5 by 6.5. We're then going to specify our clarity rankings. So this is a list of the clarity rankings. So here we have I1, SI1, psi2, VS2 ds1. Dvb-s2 and VV S1. And IF SO, these come from the clarity rankings that I found on this Wikipedia article. So they are a number of different ranking categories and these are the ones that are included in this dataset. So they're all various categories. I'll be there flawless or diamonds with some flaws and then slightly occluded and diamonds. So we can see had the clarity ranking effects the price in our final figure. So now we can finally start using Seaborn are fine blush. So Use SNS. Dont scatterplot. And then we specify and on our x values are equal to Karen. Or y axis will be price. The hue will be the clarity. So this is where our clarity rankings will come in. The size will be equal to the depth, which is another one of the features in the dataset. Dash a refers to the, I think the top of the diamond to some specific perished on or the coach was made. So then we're going to choose the hue ordering. So the hue order and dash will be clarity ranking. We ultimately to specify the sizes. The sizes will equal. A tuple of one comma h, r line width will be 0. And finally, we can include our data which is equal to diamonds. And t axis that we're going to use is a x. Now, we can finally show what we've thought into using plt.plot o. And if we run that, you see now that we have this really interesting plot, which clarifies how the clarity and the depth of the diamond influences the price. So you can see here, a lot of debt cheaper diamonds, they have very low carrots, which I think refers to the overall size of the diamonds. And the clarity is in this m i1 level. And then for the higher price diamonds, they have really learned carrots. So you see all the values up here are for very high carrots. But also there is carrots which have either very good clarity or good depth, which can also influence the price. So looking at the clarity, we can see that this i stands for included on these are diamonds dot obvious inclusions that are clearly visible to a train greater under a Tenex magnification. So these are the lowest quality diamonds, then they're flawless category is the fl, or internally flawless, which is the I f. So you can see that these blue clarity switch or these ones that are included. And you can see that these usually fetched the lowest prices for each of the carrots. Then as we're starting to get to our flawless on higher-quality diamonds dot have less flaws. You can see that the dramatic he puts the price up. So that's where you see the sort of purpley on gray ones at the top of the scale. And you can see these are cause a big increase in price. We can also see how the carrot affects the price. So if you have a big diamond and even if it is this blue color, because it's five carats, it will also be very expensive. So in this case, we can see in one figure how to detect by the size of these points and the color of the clarity. And also the carriage leads to a difference in price. So we're being able to contain a lot of information in this one figure. 54. Scatter Plot Matrix: Okay, so in this tutorial, we're going to continue our look at Seaborn. And in this case we're going to look at using a scatterplot matrix. So scatterplot matrix are one of my favorite plots, especially when doing exploratory data analysis because you can get a really good overview of all the datasets and each of the features actually interact with each other. So first of all, we're going to import seaborn as SNS. And then we're also going to import matplotlib as well as PLT. Finally, we're going to set our style. So using SNS dot slash style, that style equals two ticks. So in this case we can load the dataset from C born again. We're going to use dataframe and we're gonna set S and S dot load dataset. And we're going to use the Iris dataset diarrhea used before. So this was the data set errors. And to create a scatterplot matrix, and C1 is very easy. So all we need to do is do SNS dot pair plot. And then we're gonna pass in the DataFrame. And then in this case we want to set the hue equal to the species. And finally, we can just do PLT and not show, to show what we've created. And if we run it, it might take a while because there's a good bit of data. But eventually the plot will show up. And you see here the interactions between the different species. So we have the setosa very similar under Veronica. And you can see how the sepal length and sepal width interact with each other. You can see how the petal width is related to the sepal length. And only needed to do was to call this function called parabolic and pass in D dataframe. And we're just setting the hue equal to species. So this is a really simple way that we can create a scatterplot matrix. And we only have to pass in our dataframe and basically see Warner's doing everything else. So if you click an edge, you can see a lot of the other options that we can set. But I think for the default parameters, you can get a really good-looking diagram. 55. Violen Plot: Tutorial, we're going to take a look at using a violin blush. So a violin plot is very similar to a boxplot. Instead of using air lines to show the statistical difference, it sort of creates this file in shape which m goes further out from the y-axis as more points are included. And is able to give you a really good overview of the density of your data. So again, we're going to import seaborn as SNS. And we're also going to import matplotlib. But I was PLD. In this case, we're going to set our style using SNS. And we're going to set the style equal to avoid grid. And we're going to set the Polish pasta l. So once we have imported all the modules that we need, we can now load our data set. So we're going to use the tips dataset, which we can load from seaborne using SNS dot load dataset. And we're going to load tips. So now that we have our dataset on A-modules, we can start drawing our violin plot. So it's really easy to access this and C1. So it's just SNS dot violins. And our x is going to be equal to t d t d y is going to be equal to the total bill. Oops, I got y is equal to total bill. The hue is going to be equal to 1 third, they're a smoker or not. So this is one of the characteristics we will use to find out she was leaving the bigger tips. The Splish DEM, violin plots to show them directly compared, compared with each other. So we're gonna say Splish is equal to true. And we're going to put enter equal to ct. So finally, we just need to include data, which is tips. Then we can short Bosch using PLD, that shell. So if we run this, you see here we have this violin plot. So this gives us a really good overview of our data. So in this case, we can see how being a smoker or non-smoker effected the total bill. So on thursday we can see it's a hush D datasets are almost identical. So the median values are the same. The total bill is just 18 on Friday, and that's the same for both of them. On Friday, are smokers seemed to be spending much less and are non-smokers spending a bit more. So from this you can see how the density is very different. So there's quite a range of values for the daily smokers. For the non-smokers, they're quite condensed into this space. And there you have a higher total bill over n 20 for the average. On Saturday and Sunday, we can see that the plots are a bit different than during the day. Days of the week are quite similar. So there's a greater variation in the total bell. So on Saturday, the median value is 20 for the smokers. And the non-smokers are expanding slightly less on the same on Sundays as well. So in the weekend are smokers seemed to be spending a bit more and the total bill done are non-smokers. And the differences in total bill are slightly different than during the days of the week. So we can see on Friday are non-smokers seem to have quite a condensed datasets. So it's all between an attorney and 95 Bush on Saturday and Sunday. There's a huge variation and the total bill, so you can go all the way up to 60. So this gives us a really quick overview of how different factors, such as being a smoker, can affect the total. 56. Kernal Density Estimation: I just wanted to give a quick overview of a, another plot that you can use in C1 that we've also had experience wishing matplotlib. So in this case we're loading in the classic Iris dataset and we're going to plot two of the species. So there's cytosol and virginica. We've set up our figure using matplotlib. So we have our figure access using plt.plot, set the aspect equal to equal, and we're going to use a KD flush. So this is a kernel density estimation, and we've used them before in matplotlib. And the syntax is very similar in seaborne. So we're specifying the color maps. We can specify the shade where we want the y values we're going to use. So in this case we're using the setosa sepal length. There, virginica sepal length. And so we're adding then some labels to the plush. So adding labels to the plush is quite similar to matplotlib as well. We're just using AX dot text. We're specifying the place that we want to push our text on, the actual text W12 include. So if we run this, you can see is that it gives us this KDE blush of water a data distribution would look like for the virginica and the setosa flares. And this is their sepal length and sepal width. So you can see the setosa have a lower sepal length and a slightly mediums I Paulette from Rand, say three to 4.5, but the main difference is in the sepal length. So that can be used to the key identifying characteristic between these 2 third. 57. Annotated Heatmap: So in this tutorial, we're gonna take a look at annotated heatmaps and seaborne. So heatmaps can give you a good indication of whether the most popular points or the most popular times, any time series. And in this case we are going to be looking at flight data. So to see how the mentor flights people are taking changes by the month and date of the year. So first of all, we're going to import seaborn as SNS. We're also going to import matplotlib as PLT. Then we're going to set the default style by just using SNS dot slash, and Amy an empty. Then we're going to load our example Flight datasets and convert it to long form. So we're going to use flights long and set that equal to SNS boatload dataset. And we're going to load the flights dataset. So actually one of the really great things of ETC1 is the amount of datasets that you can load on it. So it makes it really easy to experiment with new techniques and visualization options because you have all these data sets built into right away. And so we're going to update our flights to be equal to FlightStats dot peevish. And we want T month, year on passengers. And so once we've loaded all our data, we can start by drawing our figure. So we set up our F, So our figure on axis and set that equal to PLT. Let's subplots. And in this case we want to have a figsize equal to nine by six. We can then draw our heatmap using SNS, heatmap. And for dash, we only need to pass through our flights. We want to set annotations equal to true, are going to specify our format. So format that's equal to N D. And we're gonna specify the line which equals 0.05. and our axis axis. So once we have all that setup, we can just use plt.plot to sharp blush. And now we have this annotated heat map of the amount of flights by passenger over the years. So we can see that July and August tend to be the most popular month, but we can also see how it's increased turret years. So in 1949, there was only about a 150 books. This is increasing to 622606 over the years. And even in the winter months, it's gone to six N32. So we have our color barrier here at the side. And it gives us an indication of the amount of values just by the color as well. So we can see here that there is a very high heat map or engineer. And we would expect this as this is the summer months and also the most recent years. So we can see that lying has become popular during the fifties and sixties, would a big peak in the middle for the summer months. So this is the final lecture of the course. I want to congratulate you for finishing it. I hope you've learned lots matplotlib by T born. And you will be able to create really impressive data visualizations. If you found the course to be useful, please leave the five-star rating as this will really help me out. Aren't good luck. Wish all your future plots.