transcribe

Chapter 7.1 - Visualization

Nathan Kutz · 19m · transcribed 17d ago
More from Nathan Kutz Business
𝕏 Share ▶ YouTube 📥 PDF 🤖 .md

Section Insights

# 0:06

Importance of Visualization

Why is visualization important in data communication?

Visualization is crucial for conveying information effectively after computations. It enhances communication and helps in presenting results professionally.

  • Good visualization is a vital skill for data presentation.
  • Standard plotting functions often lack the quality needed for professional use.
  • Investing time in creating high-quality graphics pays off in effective communication.
# 0:49

Building Professional Plots

What are the key elements to consider when creating professional plots?

To create professional plots, one must adjust font sizes, line widths, colors, and add features like titles, legends, and annotations.

  • Customization is essential for creating visually appealing plots.
  • Elements like legends and annotations enhance clarity and understanding.
  • Avoid default settings; they often do not meet professional standards.
# 0:58

Using LaTeX in Plots

How can LaTeX enhance the quality of plot labels and titles?

Using LaTeX allows for the inclusion of mathematical expressions and Greek characters, improving the visual quality of labels and titles in plots.

  • LaTeX integration provides a professional touch to plot annotations.
  • Mathematical expressions are more readable and visually appealing with LaTeX.
  • Proper labeling is crucial for conveying complex information clearly.
# 1:28

Annotations and Arrows

How can annotations improve the effectiveness of a plot?

Annotations allow for highlighting specific data points or trends, making the plot more informative and easier to understand.

  • Annotations can direct attention to key features in the data.
  • Flexibility in annotation placement enhances plot clarity.
  • Effective use of arrows and labels can significantly improve communication.
# 1:44

Saving and Sharing Plots

What formats can plots be saved in for sharing?

Plots can be saved in various formats such as PDF, JPEG, and PostScript, making them easy to share and include in reports.

  • Multiple file formats ensure compatibility with different platforms.
  • Saving plots in high-quality formats is essential for professional presentations.
  • Consider the audience and medium when choosing a file format.
# 2:20

Introduction to 3D Plotting

What is the significance of 3D plotting in data visualization?

3D plotting allows for the representation of functions that depend on two variables, providing a more comprehensive view of complex data.

  • 3D plots can reveal relationships that 2D plots may obscure.
  • Understanding the dimensions involved is crucial for effective visualization.
  • 3D plotting adds complexity but also depth to data representation.
# 3:00

Types of 3D Plots

What are the different styles of 3D plots available?

Different styles include surface plots, contour plots, and wireframes, each offering unique ways to visualize data.

  • Choosing the right plot style depends on the data and the message to convey.
  • Surface plots provide a solid representation of data, while contour plots show levels of values.
  • Wireframes can be useful for simpler representations but may become cluttered with dense data.
# 3:40

Color Maps in Visualization

How do color maps enhance data visualization?

Color maps help differentiate data values visually, making it easier to interpret complex datasets.

  • Color maps can convey information about data density and value ranges.
  • Choosing appropriate color maps is essential for clarity and accessibility.
  • Consider color blindness and printability when selecting color schemes.
# 5:00

Final Thoughts on Visualization

What should be the focus when creating visualizations?

The focus should be on clarity and effectiveness in communication, ensuring that visualizations accurately represent data and findings.

  • Invest time in creating clear and informative graphics.
  • Good visualizations enhance understanding and retention of information.
  • Regular practice in plotting can significantly improve skills over time.

Transcript

0:06 We're going to begin about talking about visualization. This is actually one of the most practical things to be thinking about is once you've done some computations obviously to convey information to other people, it's usually going to come in some kind of form of visualization. So building good visuals is really an important skill to learn and there's a lot of things you can do within the Python environment to build really professional looking graphics. very rarely can you just simply use the standard plotting functions that they have because they typically will not produce high enough quality results. And so you have to play around with both the font setting sizes, the line widths, the colors, everything that you might want to do to make a professionallook plot. So part of we're going to talk about is how do you build good visualization tools and what are the mechanisms to do that. So let's start off with a a basic thing we want to start with. Let's start off with plotting two functions. So here's the two functions, a cosine and a s times an exponent. And so we're going to plot these two functions f and g. Again, if you just use the standard plotting routine, you'll get a picture. But one of the problems is that very rarely could you actually use that picture, for instance, and show it in a paper or it's it's just simply not professional enough looking. especially after when you need to really clean things up and make make it look very nice. So let's first of all talk about the basic structure here of building these things up. We're going to bring in map plot lib as plot and that's going to be something we bring in from Python. We're going to define a domain. Here's our domain.

1:38 Here's our line space going be 100 points in this domain that goes from -10 to 10. We're going to plot the two functions f and g. And there is where they are defined. And so now what we want to do is if I wanted to make a very professional looking plot, there's a lot of things I might want to do besides just pl it. Plot it as is. So again, visual communication is probably one of the most important things that you're going to be doing once you've done a computation to show others the results of of what you have. So let's start off for instance with the plot I want to show which has a lot of let's call it the extra features you need to make a very nice plot. So let's go ahead and show it here. So for instance here I've shown you a subplot type style. What I have here is I have a title on each on this axis here. I have things like for instance here I've overwritten the y-axis with min and max. I'm going to show you how to do that. Or even here look at here. This goes from negative L50 L. I've decided where I want my tick marks. I've even overlaid them with things like minus L and L. I have a legend in here. I have actually able to put in latte itself, right? I have this ski here. I have latte here as well, space C. So these are the kind of things I want to play with along with line wid widths that I would have with each plot and things like annotation, an arrow with a label on this. So these are all extra features that you would need to learn how to do with the Python environment. So, if you clone the repo, you of course have the the notebook that did this. Part of what you want to do is start off for yourself a nice set of notebooks where you make very high quality graphics because this is very important when you want to communicate your results and also when you want to want to produce a a plot that it's actually worthy of being in a in a in a in a writeup or a journal publication.

3:35 You should never just use the default settings. They are typically not good enough. The line widths aren't good enough. the font sizes aren't good enough. You can control everything with a simple a few simple commands that I'm going to show you here. And so I, you know, I would always advocate spend time making good plots. It will make a big you know, influence on what you do down the road. Okay. So, first of all, let's talk about some basic things we want to do here. Here's the plotting that we want to do for the sub routine.

4:04 So, you have a subplot command 211. So, it's two rows, one column, the first plot. And here, notice what we're plotting here. The XY you get to pick a color. These are all color inverted here. So like originally the color was with a back with a white black background. So magenta and a black. And I've labeled one f ofx, the other one g of x. By the way, I could have put these by the with dollar signs around them to make a latte version of the f ofx and g ofx as it is now. It's just basic text.

4:35 And here I've made essentially a title for the first plot. And notice what I did here. If I put dollar signs, what's in here is latte. So if you use latte, you can make some very nice latte commands. This is probably the best way to make Greek characters or mathematical expressions directly, which is you can do it here directly in here. You give the title and notice what I can also do. I can specify the font size of 12. So you can easily play with making the font sizes bigger or smaller which is actually really important because this plot is going to show up often times in a report and it could be a single column or it could be in a double column width and so depending upon where it shows up you want to pick this text size to be the right size and that's how you do it here with the font size commands. So some those are some of the basic features of this plot. Let's talk about other things that we've added in here.

5:30 In addition to that, notice here with the commands here, X I've got the X and the Y ticks and the Y X ticks and the Y ticks. I can tell you where I want my ticks to be. And notice I can overwrite them with what I want there. So, wherever the -10 is, I'm going to put a negative L. And where the 7.5 is, I'm going to have it blank. Where the neg five is, I'm going to put a neg five. So, in other words, not only can I specify where the ticks are, like I've done here, but then I can overwrite what's actually represented in those ticks, which can be actually really important when you want to highlight certain information. Like for instance, in this one here, the the L to L is the domain size, and L of course is 10 here.

6:16 But I don't have to express it from -10 to 10. I can express it from negative L to L, which is something nice. So if I redo a computation and I change the 10 to 7 12 or 20, this already just says it goes from L to L, which is very nice for us. So you can do this both with the X labels, the Y labels down here. I'm also putting here the X label and notice in the X label I put in latte commands directly there as well. So the latte itself can be put in anywhere and you just put dollar signs around it and then you can execute latte itself. Latte itself is the best way to represent mathematical formulas, Greek letters, expressions of this form. And so you can make a plot that's very nice.

7:01 Whereas if you just try to do it with normal text, it's just not going to look as good unless you use latte. So that sets that up for you. Let's go ahead and actually now talk about that arrow, the annotation here. So the annotation is right here. So you have an annotate function which allows you to prescribe where the arrow starts, where the arrow is going to end, and what you're going to put in that area. You can specify the line width of the arrow. All of that can be done automated in this fashion. So you can make really nice graphical plots that can take a very basic plot and turn it into something much nicer looking. So for instance here, this is pointing to the coine. So you can label this one here. That's the cosine, right? It points right towards here. So it allows you all this flexibility and making very nice graphics. And this is just an illustration of the things you might want to do in a plot. And then when you want to save it, of course, you can always write it out as a PDF file, a postcript file, encapsulate a procript, JPEG. These are all the options that you can do. So you plot it all, you show it, and then you can plot it. So this is sort of a very standard thing you want to be doing and thinking about when you're doing computing because graphics are the most important form of communication to your colleagues. And so make sure you spend the time with graphics. There's nothing worse than bad graphics. So you might have this amazing result and you have a terrible graphic.

8:29 no make a nice graphic. Spend some time build out your nice plotting routines and then you can use them over and over again. And once you have a nice plotting routine you like, you can actually just bring that in and use it across a bunch of your workflow. Okay, so those are 1D graphics, right? So sorry, it's 2D. It's an X and Y plot. We're going to go now to three-dimensional graphics, which is an X direction, a Y direction, and finally, the Z direction is sort of the function you're plotting. So it's a function of X and Y. So it's really a 3D plot, but really of a of a 2D function.

9:04 So f ofx and y. So how we might do plots like this is here's what they might look like. So this is a generalization of what we just showed which is on this bottom axis you have the x and y directions x here y here and the z direction is plotting the value of the function. So it's not a third direction. It's just the value of the function f at x at each x and y position. So right away a 2D function requires you to have a 3D framework to plot it in. Right? So this this already makes it a little bit complex for plotting. For the most part a 2D function requires 3D. A 3D function would require 4D which makes it very challenging for us. So for us this is about the best we can do is do these nice 2D slices of data. So here's some different options for plotting this.

9:54 This is a a single plot. This is the same plot but on the bottom here there's a contour. There's both the plot and a contour below it. So it's a double plot in some sense. This one here is contours across this. And this is a wireframe. So these are all different options depending upon the style you choose or prefer and also if you can print in color or if you need to be in black and white. So these are the kind of options that you might have available to you.

10:19 And let me show you how to do these. So first of all let's make a function here. I've defined an X direction, a Y direction. I'm going to make this thing sort of a mesh grid and make a function right here to plot. And this is just a spiral wave essentially what you're looking at here. And here's the function for that. So I have discretization in the X direction, discretization in the Y direction. and so once I have that, now I can define my plot. This is what it looks like. But now let's go walk through each one of these to show you how this might be plotted. So the first one here is we're going to do a subfigures, right? And I can pick the figure size. I make a figure. There's going to be four plots in this figure.

11:01 And so first of all, I'm going to add plots here. And 2 to 1 means this is number x plots, number of rows, columns, and which plot? So it's 2x two in the first plot. So that's this corner here. And the projection is 3D. So you have to tell it that or else it doesn't know that it's trying to build a 3D projection of this 2D thing. So the first one is just a surface plot plot surface. You give the x coordinates, the y-coordinates, and the value of the function itself. And here your color map. You can pick some color map, cool warm. There's a lot of different options. And by the way, this is color inverted. So you're not actually seeing the cool warm color map, but you can pick a hot color map, HSV. There are so many different options. So you can pick a style you like and then you can like plot that in there to make your color map. You can also specify a color map if you like. It gives you that optionality.

11:55 What I've also done here is removed all the X, Y, and Z axis just to show the plot directly by itself without any X or Y axis. I could always bring the X and Y back in if I'd like to make it a very nice plot. And we'll show that later, but for right now, just want to think about what's the best way to visualize that 3D. So that's one possibility is the surface plot that we have here.

12:17 Another possibility now is if you move over to this one here which is here 2 two two so two rows two columns second plot that's one here and notice what I have here I have a surface plot and a contour plot so if I do the surface plot that's what you're seeing here the surface the contour plot is below it so if you look carefully underneath there there's contour lines of constant amplitude which are colored by the height okay and again you can pick a color map the color map has to be the for the contour and the surface because in the same plot, but it allows you this overlay of extra information potentially. Now, we'll see we can do better than just overlaying like this.

12:58 We'll make some better plots as we go down the road to really play around with our visualization capabilities, but right now we're just kind of figuring out what are the options for us in terms of visualizing 3D. The third plot is here and what this is right is contour F. So instead of contour contour f basically plots contours at different levels. So each one of these is sort of a a different level of that contour of a constant value of the constant contour value. So it's kind of an interesting structure.

13:30 It's basically this but now sort of in a different representational framework with the contour f command. Again the cool cool warm color map that we could use on this. So just another option if you like it. And the fine one here is essentially a mesh frame right here. Okay, a wireframe. So the wireframe is a mesh on this thing. And so here it is. It looks like just a wireframe sitting over over the over the plot. The wireframe is nice if you're going to plot in black and white. The wireframe is okay if you have a limited number of points, but you have a lot of points.

14:07 The wireframe becomes too dense and then you can't see through it anymore. So these are just some options that are available to you in sort of this 3D representation of this 2D surface. There are other options for us. Let's consider by the way if you want to plot it out again you can make this figure plot it out as a a postcript figure PDF JPEG whatever you want. There are a lot of options that you have available to you pipeline, but it's just you tell it how you want it out and it'll plot that and then you can take that put it in a PowerPoint or put it in a in a a latte document and so forth.

14:44 we could also plot it from a top view. So this is a a top view or contour view of that surface. So here it is if you have if you see the grid lines on it. So in other words, if you plot the contour just as it is with the grid lines in both X and Y or you can in fact just use it in in an interpolated setting. So it smooths over and it doesn't show you the grid lines. And so often times this is a very nice representation of of the data itself.

15:12 these are fairly easy to make. Okay. So the first one is called the peak color and peak color just gives you the X, the Y, the value. Okay. And then you can pick the edge colors. So here in the first one with P color if you just pick the edge values be black of course this is color inverted so they'll show up white you can pick the width so you can pick the color map everything you want here that's the first plot the second plot this is you do you here is the it's the p color again the x and the y and u and this is sort of the default which is it's just going to give you a smoothed out version and I don't want to see the edge colors. So there is no edge color. It just basically gives you an interpolated version. So the peak color will do that unless if you want to see the edges, you got to put here what the edge color you want on that to be. So this is another representation. So you're looking at a top view of this two-dimensional structure. You can even put if you'd like a color bar on it so you can see what the colors represent in terms of actual values. So that's a possibility for you. Okay. All of that can be done. But again, different possibilities for visualization.

16:25 Here's another picture of this just showing some of the different color maps available to you. This one here is just completely all red. It's colored in one color on that surface, right? Which can be nice. Here is a color map which is colored by height. So the top of this is more white and yellow, which is hot, and the bottom is black, which is cold in some sense. This is in the grayscale version of it. And that's the grayscale version of this. Now, notice here though, too, there's some extra interesting features, which is it's partially see-through. So, you can control all of these how how see-through they are. So, you can see what's behind the surface. Sometimes it can be very helpful and sometimes it can just create clutter. So, it depends a little bit on what you're looking for and the actual plot you're trying to make. You can play around with how see-through a plot like this is. But again, these are different options. Now, I have it on a white background, which is more likely what you're going to do. And so, you can see some of the different options for you.

17:27 Again, if you clone the GitHub repo, you can make all these plots for yourself very easily. Other possibilities. Here are some that you might have. This is like a wireframe around. So, this is like for instance in the X direction here. This is time here. And the height that you might have. And here's two options for showing this function out for yourself. One of them is a wireframe, one of is a surface. Here's how you would make these. Right, here's the wireframe command. That's the going to be this one here. You're going to specify all the different x positions and then here the y positions and then the height. And so if again the wireframe isn't so good if you have too many Y too many slices that you'd have to plot but it's pretty good if you kind of bring it down a little bit. And of course you can control how many you want to plot. And if you want to do this this is down just a surface projection which is done right here. Okay, which is the with the surface command. So again options for visualization of lots of different functions and the more complex the data the more you have to think about how you want to actually represent that data and plot it. Okay. So these are just giving you nice options. So again I want to finish with this because plotting is one of the most important things you're going to do. I always tell students over and over again just plot as much as possible because plotting conveys a lot of information to yourself but also it's the way you want to represent your findings to other people right your classmates people you know writing a report if you don't represent the data well people are not going to understand it.

19:11 If you spend some time making nice graphics is going to make a big difference for you. So again visualization even though we're not talking about doing any kind of real serious computation here we are talking about what you're going to do once you've done your computation have your results what is the best way to show these to people and to yourself and this is really important for you to spend some time thinking about >>

Summary

The discussion focuses on the importance of creating high-quality visualizations in Python to effectively communicate computational results. It emphasizes that default plotting functions often lack the necessary professionalism and clarity, urging users to invest time in customizing their graphics for better presentation in reports and publications.

- Visualization is crucial for conveying computational results to others.
- Standard plotting functions in Python often do not yield professional-quality graphics.
- Customization options include adjusting font sizes, line widths, colors, and tick marks.
- LaTeX can be used for better representation of mathematical expressions in plots.
- Annotations and legends enhance clarity and understanding of the visualized data.
- Different types of plots (2D and 3D) can be created, including surface plots and contour plots.
- The choice of color maps and transparency can significantly affect the interpretation of data.
- Investing time in creating quality graphics can improve communication and understanding in reports and presentations.

Questions Answered

Why is visualization important in data communication?

Visualization is crucial for conveying information effectively after computations. It enhances communication and helps in presenting results professionally.

What are the key elements to consider when creating professional plots?

To create professional plots, one must adjust font sizes, line widths, colors, and add features like titles, legends, and annotations.

How can LaTeX enhance the quality of plot labels and titles?

Using LaTeX allows for the inclusion of mathematical expressions and Greek characters, improving the visual quality of labels and titles in plots.

How can annotations improve the effectiveness of a plot?

Annotations allow for highlighting specific data points or trends, making the plot more informative and easier to understand.

What formats can plots be saved in for sharing?

Plots can be saved in various formats such as PDF, JPEG, and PostScript, making them easy to share and include in reports.

What is the significance of 3D plotting in data visualization?

3D plotting allows for the representation of functions that depend on two variables, providing a more comprehensive view of complex data.

What are the different styles of 3D plots available?

Different styles include surface plots, contour plots, and wireframes, each offering unique ways to visualize data.

How do color maps enhance data visualization?

Color maps help differentiate data values visually, making it easier to interpret complex datasets.

What should be the focus when creating visualizations?

The focus should be on clarity and effectiveness in communication, ensuring that visualizations accurately represent data and findings.

© transcribe · For agents Built with care and craft by Gokul Rajaram