Saving plotly Figures Video Lecture Transcript This transcript was automatically generated by Zoom, so there may be discrepancies between the video and the text. 16:33:19 Hi! Everybody! Welcome back in this video. We're gonna learn how we can save our wonderful plot. 16:33:25 We figures. So we've gone through the trouble of learning how to make a variety of Plot we figures primarily static, but with some hovering effects. 16:33:34 So why don't we, let's say, have a figure in mind? 16:33:39 So this auto mpg, figure that maybe we're really happy with so we've got this nice auto. 16:33:44 Mpg. Figure. It's got a nice title. 16:33:46 Got these nice axes labels, and when we hover it tells us things like the name of the vehicle. 16:33:52 Along with the year, the weight and the fuel economy which we have plotted here as well. 16:33:57 So maybe we're really happy with this, and we would like to save the figure to a file. 16:34:01 So the first way we can do this is save it to and HTML file. 16:34:05 So remember, Plotley is using Javascript to create a web image. 16:34:10 So the natural way that you might want to save this is with an HTML file. 16:34:15 So in order to do this, you call fig.so fig is the variable that we stored our figure in. 16:34:21 Can you do right? HTML? And then you input our file name. 16:34:27 So for me. I'm going to copy and paste this file name that I chose ahead of time, and then when I run this, we can go to our repository and we can find the HTML example. 16:34:39 And if you look here, this was saved seconds ago. So if I open this now, I have this HTML file that has all the plot we, you know, exactly the same way that it was in the Gupiter notebook, so our figure is now saved in this HTML file. 16:34:55 We can open it and look at it whenever we'd like. 16:34:58 Now, one thing you might know, however, is that this file is 3.6 one megabytes, which is a relatively large file size. 16:35:09 So? Why is that so? Whenever you save an HTML file and Plotley by default, it saves the entire plotly package within the HTML. 16:35:17 File so that way it works the way that it's supposed to work. 16:35:22 So if you don't have a setup within the file that you plan on store or folder, that you plan on storing the file in, to have sort of plot Lee package in the background as its own set of files, or its own folder files, if you don't have that then you'll have to 16:35:37 use this as it is, as the default is, in order to get it to run properly. 16:35:43 But if for some reason you have a setup that allows you to have Plotley in the background of the folder, and you don't want it saved in the particular HTML. 16:35:52 File. You can do include bluntly. Js is equal to false. 16:35:59 And now we can go and see that the file size is much smaller, much much smaller. 16:36:07 But because I do not have Plotley, Js. Set up in this folder, we can see that nothing runs all right. 16:36:15 So if I did have plot lead Js stored in this folder, then you properly stored and set up in this folder, I could run this, and my file would work just correctly. 16:36:27 But because I do not, I can't include that, and I still expect my file to work. 16:36:32 So I've rerun it so that it will work and does include the entire plot. 16:36:37 Lead package. So maybe you don't want to save your file as an HTML file type. 16:36:41 Maybe you would like to save it as the static type. 16:36:45 You can do that as well. You are going to need extra help from an additional python package called Callido. 16:36:51 You can find instructions on how to install this package from the plot. 16:36:55 Lee documentation link that I've provided here also, once you've installed the package, you'll need to go through Restart this Jupiter notebook from the beginning, and rerun everything up to this point. 16:37:09 I already have the package installed, so I don't need to do that. 16:37:12 But if it, you are installing it for the first time to get this code to run, you will have to make sure that you clear your kernel and restart the notebook and run it up to this point. 16:37:24 So once you do have Colido installed, you can go ahead and just save a figure to a static type using right image. 16:37:34 So you do fig right image and then import the file. Name with the extension you'd like. 16:37:40 So 4 options, you can use here are Png, Jpeg. 16:37:43 Svg. And Pdf. And after running each one of those code chunks we can see them here at the bottom. 16:37:49 So here's the Jpeg version. Here's the Pdf version. 16:37:54 This is a higher resolution image. Here's the Pg version, a lower resolution image. 16:38:02 And then finally the Svg version which Svg. 16:38:07 Doesn't have a way to display when you click on it when Jupiter notebook. 16:38:10 But trust me, that's there. Okay, so that's how you can save static file versions of your plot Lee images, if you so choose. 16:38:20 So now you know how to save your image as either an interactive HTML file or as a static image like a Png. Jpeg. 16:38:28 Svg. Or Pdf. In the next notebook. 16:38:31 We're going to show you how to make a dashboard using Plotley, which is maybe something you're interested in doing for various applications, or just to get practice for job applications, not web apps. All right?