Do you struggle to know where to start with the wide range of Python's data visualization
frameworks? Not sure when to use Plotly versus Matplotlib versus Altair? Then this episode is
for you. We have Chris Moffitt, a Talk Python course author and founder of Practical Business Python,
back on the show to discuss getting started with Python's data visualization frameworks.
This is Talk Python to Me, episode 384, recorded September 29th, 2022.
Welcome to Talk Python to Me, a weekly podcast on Python. This is your host, Michael Kennedy.
Follow me on Twitter where I'm @mkennedy and keep up with the show and listen to past episodes
at talkpython.fm and follow the show on Twitter via at talkpython. We've started streaming most of our
episodes live on YouTube. Subscribe to our YouTube channel over at talkpython.fm/youtube to get
notified about upcoming shows and be part of that episode. This episode is sponsored by Microsoft for
Startups Founders Hub. Check them out at talkpython.fm/founders hub to get early support for your
startup. And it's brought to you by us over at Talk Python Training. Did you know we have one of the
largest course libraries for Python courses? They're all available without a subscription. So check it
out over at talkpython.fm. Just click on courses. Transcripts for this episode are sponsored by
Assembly AI, the API platform for state-of-the-art AI models that automatically transcribe and understand
audio data at a large scale. To learn more, visit talkpython.fm/assembly AI. Chris, welcome back to
Talk Python to me. Thank you. Glad to be here again. I'm glad to have you back. We originally
had you on to talk about the work that you're doing at Practical Business Python. And looking at the page
now, your last article, Panda's group by warning on the 26th, which as of recording, two days ago,
looks like you're still really active on Practical Business Python. I am. It's been a while. To be honest,
I spent a lot of time working on the course that we'll talk about in a moment. And so some of this
stuff fell by the wayside. And I think like everybody in the COVID times have been a weird
time warp for us all. So I haven't spent as much time on it as I would like, but I am getting back
into it. And as you mentioned, just put a short article up there that in some ways kind of encapsulates
a lot of what I want to do with Practical Business Python is I'm writing in this specific article in general
on the blog about problems that I encounter that I think can help other people. And this was a short
article about some kind of gotcha behavior with group by that I've been bitten by a couple times.
And this most recent time, I decided, you know what, I need to write about this and share it with people
so that hopefully they're not going to fall into the same traps that I had.
I love when you write something as kind of a note for yourself or a roadmap for yourself. And then
later you go back and you search for it. And you're like, I got to remember how this went.
And like hit number one as your result. You're like, okay, I guess I don't remember this,
but I'm going back to it. And I, you know, my future self thanks my old self for it, right?
Yes, exactly. And sometimes I even remember I wrote an article about it and will refer to it.
And then a lot of times you're right. I'll do a Google search. I'm like, oh yeah,
I did solve that before.
How interesting. Yeah, cool. What a great resource. People should be definitely checking
this out. If you know, you want to do data science, Python data science intersected with
Python. Of course you were on the show a couple of times ago, way back on 2019 and the before times
escaping Excel hell with Python and Pandas. Basically you were making the case for
using the Python data science stack instead of Excel, right?
Yes, absolutely. Yeah. And you know, the blog and a lot of my experience has been
doing data analysis, data manipulation, data science, and trying to leverage the power of Python.
And most people in a business setting, their go-to data science, data science tool or data analysis
tool is Excel. And it has its place. I'm not advocating we get rid of Excel, but I think there
are a lot of things that we can do with Python that are much quicker, much less error prone and
much more efficient than trying to do it in Excel. And Excel is one of those tools where there's such a
wide range of usage. There's some people that are experts and can do really complex, very efficient
things in Excel, but there's a lot of people that treat Excel like the proverbial hammer. Everything's a
nail. So you try and use Excel to do everything from data cleaning to building out your financial
statements to, I don't know, machine learning. And it's probably not really the best tool for all of
those things. I think Python really fills a nice niche and had the good fortune of using it for a
lot of different types of activities in my business career and wanted to talk about that in the podcast.
You know, one thing that occurred to me, just thinking about the code that I've seen for like
visualizing data and so on with Python compared to writing algorithms or web apps or something,
it seems to me that the amount of Python that you have to know and able to maybe import pandas,
load a CSV and then graph it, you almost hardly need to know Python at all. And it's more about
knowing the APIs of the various visualization frameworks like Mapplotlib or Seaborn, right?
No, absolutely. I agree completely. I mean, you basically need to know, like you said, how to
import and even backing up probably the most, the biggest challenge is getting Python set up on your
system, depending on the system you have and everything, getting your environments all squared
away. But once that's done, you're right. The data visualization libraries, no matter which one you
choose, essentially are knowing how to call functions.
Yeah, exactly. And they all often seem to have their own little DSL domain specific language for
what they've decided they're going to do, right?
Yes, exactly. And I think that's, you know, part of the challenge is everybody thinks a different way.
And sometimes like a library might make a lot of sense to you, but other people, it doesn't. And so
that's a lot of where I think some of the challenges in the visualization landscape are,
are trying to find that right API that makes sense for the actual business problems or
visualization problems that you have and how, how it fits in your brain.
Indeed. So if people are coming from a business perspective and maybe Excel is where they or their
colleagues have been working, I definitely recommend people go check out episode 200. And then there was
also 10 tips to move from Excel to Python, a lot of common themes here.
Yes.
So normally at the beginning of the show, I ask people how they got into programming in Python.
I've got you to answer that at least once, maybe twice, but probably a third time is,
is not required. So just give us an update on what you've been up to.
Sure. I am still working in the medical device industry. My job doesn't require Python, but my job
does involve a lot of data analysis and working with not necessarily large sets of data, but sometimes
data sets that are big enough that it's a little bit painful to work in Excel. And I just continue to
find Python as the tool that I reach for when I need to do data analysis. And I continue to use it to
build repeatable data analysis pipelines. I use it to clean data, maybe take external data that we buy
from a third party and integrate it with internal data sets, or as we'll talk about doing data
visualization. I think there are a lot of things that Python can do from a data visualization perspective
that are easier than trying to use Excel or some of the other tools that are available in a traditional
environment. So I continue to live and breathe Python. And I would say, you know, every week,
I use it a little bit, some weeks, a lot more than others, but continue to enjoy kind of that blend of
Python, real world problems, and not just for software development's sake.
Do the people you work with, since program is not officially like your title, do they look at you
as kind of like a wizard?
A little bit. Yeah.
Yeah.
They do. And I mean, I've done one of the things that I've worked on was a forecasting tool to help
us forecast our business performance, you know, anticipate what that's going to look like, which I
think a lot of people did over the COVID times trying to forecast was extremely challenging. And they just
call it, well, what does the Python tool say? So they don't really, you know, get what the underlying
libraries are, what's going on, but they do associate my name with Python. And I don't know if they really
understand what it all means. I certainly try and explain it, but at the end of the day, you know,
happy with the results. And like you said, they do kind of think there's a little bit of a superpower,
as you frequently say.
That's fantastic.
Or knowing that.
Well, when you go and look at the basic things that a lot of the tools we're going to talk
about, the frameworks that we're going to talk about result in, you could easily look over at
something like Excel and go, well, six, one, half dozen of the other, that kind of the same,
right? But then the amount of customization and specialization that if you go a little bit
beyond just the, give me a histogram of this data, but you know, you dig into it a bit,
it goes far beyond what things like Excel are able to do.
Yes, absolutely. And it's funny you mentioned histogram, like even a few years ago, there wasn't
even really a histogram function in Excel, you know, kind of one of the basic functions I use pretty
much for any new data set is the histogram and Excel didn't have one out of the box. You could build one,
but it wasn't there. And I think that just kind of speaks to Excel is approaching,
approaching visualization from a very different perspective, I think, than the Python tools.
Excel is much more of a, how can I quickly create something and kind of guide the user through it,
and then give them almost infinite options to customize the visualization. So you can go in and
tweak any individual data point or axes or colors, which, you know, is useful for getting started,
but I don't think it scales very well. And it also doesn't have some of the more sophisticated,
complex visualizations that you can do with the Python libraries that are out there.
Like Sunburst and other amazing things. Exactly. Yeah, cool. All right. Well, let's mention your
course real quick, because what we're going to cover today is inspired by the course. It's not the same
thing as the course, but you recently published a course over in Talk Python, Python data visualization.
This is really nice because the visualization landscape is so diverse and varied, and it's hard to pick,
I think, what should I choose? How do I find something that, as you say, fits your brain? How do you find
something that's modern and maybe is interactive or is good for publications? And so in this course,
you know, you kind of just do a survey of many of the popular options. You want to give a quick
elevator pitch on this and then we'll dive into the topics.
Sure. Like you said, I think the Python landscape is, or Python visualization landscape is so rich. There
are so many options and many people are discouraged and don't even know where to start. And I think when
you try and marry up that landscape with the different types of problems you can solve with visualization,
it really requires you to spend a little bit of time with each one of the main libraries or several of the
main libraries to think about how they're going to solve your problem. And so the course steps through
many of the common libraries gives you, like we were talking about, the amount of Python that you need
to know to do visualization is fairly minimal. So we don't spend a lot of time on Python. It's more about
the API and how to interact with each visualization library to use it in the way that it's intended.
And then I also think it's important when people are thinking about visualization,
it's not just about the library. It's also about thinking about visualization. And as I point out in
the beginning of the course, visualization is a really broad topic. I mean, there are computer science
classes that you can take a whole semester on. There are many, many books that are really strong.
Edward, tough day comes to mind or tough. Yeah, exactly. Exactly. And when you start thinking
about visualization that way, it changes the way you approach visualization from the Excel approach of
how do I just build a bar chart to what is the information I have and how am I trying to convey it
to the end audience? And so I spent a lot of time talking about that. And then I also think that there
is a data manipulation component to this. Once you start to understand how to structure your data
correctly using maybe not correctly, but most efficiently for data visualization. Once you start
structuring your data in that tidy format, then it's very easy to iterate on your visualizations
and zero in on what's going to work best for you and your end users. So that's what the course talks
through. It talks to the concepts, real world examples of developing visualizations using many of the libraries
we'll talk about and then how to customize those visualizations from very basics all the way up to
building custom dashboards that can be highly interactive and potentially deployed for others to use.
Cool. Yeah. I definitely learned a ton going through your course. It's over at talkpython.fm
slash data viz. People can check that out. Let's get maybe a high level landscape. So view of the landscape
before we dive into these topics, because there's different branches of this, I guess you would say.
So there's a GitHub repo that you point out by Nicholas Rogier. I'm not sure how to say his name. Sorry, Nicholas.
This is an adaptation of Jake Vander Plaats' graphic about the landscape here. And so, you know,
how's this picture fit for you? Do you think this is pretty accurate? Let me see if I can.
I do, because I think it points out a couple different things when you start thinking about visualization.
So one of the key things that you can
glean from looking at this and for the people that are listening,
it's a kind of starburst plot and
you've got a whole bunch of linkages between these different visualization libraries.
And something that jumps out is
Matplotlib is at the center of many of these libraries
and it's the foundational tool that's used to build other libraries.
And so I think that's a key concept.
You can use Matplotlib on its own
or knowing Matplotlib makes it easier to use some of these other libraries that are built on top of it.
And the other thing is not shown on this, but, you know,
from a history perspective, Matplotlib is sort of the grandfather of all
Python visualization libraries.
It's been around a long time and what you see on the, for people that can see the visualization,
on the left-hand side,
JavaScript visualization is a little bit more modern, like you said,
and what people expect when you think about an interactive visualization tool.
And so that's a different approach for visualization that has some pluses and minuses.
So you've got that Matplotlib and JavaScript,
I think are the key distinctions for how libraries are constructed for visualization in Python.
And there are some other ones, there are some other libraries,
but the two that I really focus on are either Matplotlib based or JavaScript based.
Sure.
And the Matplotlib side, we have things like Matplotlib itself,
but also Pandas and Seaborn and Scikitplot, GGplot,
stuff that people may be familiar from there.
And then on the JavaScript side, we've got Bokeh and Plotlib,
some of the more, as you say, interactive ones.
And D3JS is in there as sort of a foundational item as well.
Exactly.
Altair.
I don't even see Altair in this list.
Maybe it's in there somewhere, but it is.
Yeah.
It's over there hanging out close to Matplotlib.
Exactly.
Yes.
More strongly related to JavaScript.
Got it.
The third one in the three main branches here is OpenGL.
What do you know about the OpenGL ones?
Yeah, it's a good question.
I don't use them a whole lot.
I don't have a whole lot of experience with them.
I think there are certainly maybe certain like very high volume data analysis that might be
where performance is really important, where some of those OpenGL libraries,
I think were originally founded.
But I get the sense that most people are gravitating towards either those Matplotlib or the JavaScript ones that we've talked about.
I don't have as much experience nor see as much development there with those libraries.
Yeah, maybe they're about visualizing changing data that is flowing in real time and you can actually see a change because, you know, OpenGL is basically a graphics library for animation, right?
Sure.
Yeah.
I think that real time component is a good distinction.
Yeah, probably.
Now, before people run fleeing to the hills, just because some of these projects are grouped under JavaScript doesn't mean you have to write JavaScript to use them, right?
Correct.
Absolutely.
Yeah.
And all the ones that I cover and the ones on here actually have a really nice API on top of it.
The JavaScript is abstracted away.
And in some ways, there's some benefits, like I'll call it Altair because it leverages VegaLite.
And anytime that underlying JavaScript library is updated, you kind of get all of those benefits for free through Altair.
So it's, you know, in the spirit of open source, building on the shoulders of others.
And there's a lot of benefits to having that JavaScript foundation.
And you don't need to understand JavaScript to use any of them.
Yeah.
And Altair really is like a transformation layer into a VegaLite definition, which is then processed by JavaScript to be rendered.
So there's even this sort of separation layer.
So it's not like you necessarily have to change your code to pick up the changes there.
No.
And I think at some point, depending on how deep down the rabbit hole you go, there could be points where, okay, it is really,
if you're doing something highly custom or something really unique, understanding what's going on under the hood could be useful.
But you can get pretty far without having to know that.
Maybe you're trying to make a book or an article and you need something just so you're like, you know what, I'm just going to dump out the VegaLite definition and just add two things to it, but create it through Altair.
Exactly.
This portion of Talk Python to me is brought to you by Microsoft for Startups Founders Hub.
Starting a business is hard.
By some estimates, over 90% of startups will go out of business in just their first year.
With that in mind, Microsoft for Startups set out to understand what startups need to be successful and to create a digital platform to help them overcome those challenges.
Microsoft for Startups Founders Hub was born.
Founders Hub provides all founders at any stage with free resources to solve their startup challenges.
The platform provides technology benefits, access to expert guidance and skilled resources, mentorship and networking connections, and much more.
Unlike others in the industry, Microsoft for Startups Founders Hub doesn't require startups to be investor-backed or third-party validated to participate.
Founders Hub is truly open to all.
So what do you get if you join them?
You speed up your development with free access to GitHub and Microsoft Cloud computing resources and the ability to unlock more credits over time.
To help your startup innovate, Founders Hub is partnering with innovative companies like OpenAI, a global leader in AI research and development, to provide exclusive benefits and discounts.
Through Microsoft for Startups Founders Hub, becoming a founder is no longer about who you know.
You'll have access to their mentorship network, giving you a pool of hundreds of mentors across a range of disciplines and areas like idea validation, fundraising, management and coaching, sales and marketing, as well as specific technical stress points.
You'll be able to book a one-on-one meeting with the mentors, many of whom are former founders themselves.
Make your idea a reality today with the critical support you'll get from Founders Hub.
To join the program, just visit talkpython.fm/foundershub, all one word, no links in your show notes.
Thank you to Microsoft for supporting the show.
Well, let's start with the granddaddy, as you put it, Matt Plotlib.
So, there's so many shiny new things, but you make the case that knowing Matt Plotlib is still really worthwhile and really important, right?
Because it is the foundation of so many things.
Exactly.
It is the foundation, and it's so important to know it.
And also, it is extremely highly customizable.
And I was thinking about this, and in some ways, I think if Matt Plotlib, if you stripped out a lot of the old and like everything that they've done in the last three to five years and just focused on that new, and if you could erase all the old tutorials and all the maybe ancient answers on Stack Overflow and just focused on the new stuff, people would have a much different perspective on Matt Plotlib.
I think it's hard when you have something that's been around so long and has evolved that you do get some cases out there where, okay, an API or the way they approached a visualization in the past was clunky.
But in the five or 10 years since, it's improved.
And if you use the new and improved, it's really streamlined and really easy.
So I think it's important that people not get turned away right off the bat from Matt Plotlib.
And there are certain types of visualizations where if you need a high degree of customization, if you want to print it out or include in a manuscript or a book, Matt Plotlib is really useful and powerful for it.
In that distinction about the new and the old, originally when Matt Plotlib came out, correct me if I'm wrong, it's my limited understanding, is it was somewhat modeled on the Matlab way of programming and it had this imperative API.
The new one is more object oriented, isn't it?
Yes, that's exactly right.
So there's this state based interface that was based on Matlab and for people making that transition from Matlab to Matplotlib, it was seamless, right?
And they really understood it and made sense.
But that way of doing things doesn't, it's not really Pythonic.
And so the object oriented interface is newer and is clearly the direction that Matplotlib documentation wants to steer you down that path.
And if you stay on that path, then it makes more sense, I think, from a Python perspective, and you do have a tremendous amount of power.
And I would say the other thing that I think turns people off with Matplotlib in the past is the visualizations are relatively unstyled.
I mean, they're kind of plain, whereas some of these newer libraries just out of the box make something that look really nice.
Matplotlib allows you to customize it, but that's extra work.
One of the things that Matplotlib has done is they have a new theming or a relatively new theming API.
And so if you use that, then you do get visualizations that look a little nicer out of the box and are more visually appealing.
Yeah, it does have that kind of, it looks fine, but it kind of just looks a little bland, right?
And it doesn't have that D3JS feel.
Absolutely.
So I got to give them some pretty mad props on the XKCD.
Exactly.
Have you, you've seen this, it sounds like.
Yes.
Yes, I have.
So if people, I'm sure most people out there listening know the XKCD comic, right?
If you don't go to your terminal or command prompt and run Python 3 and then just type import anti-gravity, then you'll know.
But they have this, it's been around forever and it has this sort of style of like handwritten, but not handwritten.
And one of the themes you can get is you can get the XKCD theme.
Exactly.
Yes.
And it's really cool.
And every once in a while, you'll find an article that someone put together where they show this beautiful visualization.
And then you'd be surprised that it's matplotlib and they show all the steps and you can configure it and you can make something as nice as any of the JavaScript frameworks that are out there.
But it does take some time.
There are more lines of code to get there.
Yeah, that's true.
On this XKCD thing, it might sound like it's, well, that's funny.
Like everybody loves XKCD.
I do think there is some value to presenting results, whether that be a user interface or a visualization of analysis where you want to give it this preliminary look, this unfinished look.
Right.
And so if you're going to come into a meeting and you want to say, this is what the early data says.
This is what our first pass analysis says.
You know, put it in the XKCD.
They might set that tone versus if it's like perfect and beautiful.
Like, well, you're done.
Like, no, no, we're not done.
We're not.
We're really far from done.
This is just the beginning.
I just want to give you a hint of what we're finding out.
Right.
I think there's a way that you could actually use this that would be practical.
I agree.
I mean, it's a good point.
And, you know, one of the things that I think when you go into a business setting, everybody's used to standard Excel plots.
And when you bring in something else like this, like an XKCD plot or some other plot that people aren't used to, it does get them to focus and look at it a little bit different and can steer the discussion in a little bit different way.
Yeah.
So one of the little areas that I thought was just really nice and really simple would be things like if you go and plot something with matplotlib and you have a lot of ticks along the bottom, it's very common that the words start to overlap each other.
And you're like, well, this isn't working.
And just little simple things like putting an angle on the values and the X axis can make it so much nicer.
Right.
Yes.
Yeah.
So.
And one of the things that I do have a soft spot in my heart from matplotlib on the official documentation, I think under the tutorials, they took one of the blog posts that I wrote on matplotlib and it has been incorporated into the official tutorial.
Oh, that's cool.
About how to get started.
So I think that's kind of cool.
You know, I.
Yeah.
Proud of that.
Absolutely.
Another one that I thought was nice to know about that's not at all obvious is formatters using like F string formatter type things for when the data gets put up there.
So maybe instead of having, you know, two, zero, one, zero dot, you know, some huge long decimal, you could format that as a number with no decimal point.
No sense.
Right.
I use that all the time for currency.
So if you're showing like millions, you don't want to have all the zeros.
Maybe you just format as a dollar sign to M or whatever.
Yeah.
And matplotlib makes that very easy to do.
And dates here, as you're showing are always one of those challenges with it.
With any time you're plotting something, trying to figure out the right level of dates that convey the information, but don't crowd out the visualization.
Yeah, absolutely.
So there's a lot to learn there.
But I still think a lot of people will be doing matplotlib, but also a lot of people will be choosing the newer ones.
Yeah.
Now for each of these, you came up with some pros and cons.
So for the pros category of matplotlib, you have robust options that can do almost anything and lots of documentation examples.
Yeah.
I mean, that is anything you want to do.
You can do it in matplotlib.
Yeah.
The challenge is going to be, and you can find documentation examples.
What does get challenging is because the API has evolved and changed over time, looking at the official docs are great.
But when you can't find it there and you go searching on the web, you will find a tutorial from seven years ago.
And the way they're telling you to do it may work, but it's not the most efficient way or may not work well with the way the rest of your code is structured.
Right.
Maybe it's not taking advantage of the themes or maybe it's using the stateful API instead.
Exactly.
There's a lot of reasons it could be.
Exactly.
The final, you know, challenge with matplotlib is there is some degree of interactivity, but it's not at the high level that some of the other libraries have.
So if you have a scatter plot and you want to zoom in on an individual plot, look at the data, it's not as easy to do in matplotlib as it is in some of the other libraries.
The other pro that I'd say with matplotlib is if you are trying to get your visualization in another format.
So you're trying to put it in a document, you're trying to put it in a PDF, SVG, you know, any kind of graphic format.
Matplotlib supports that out of the box.
It's very easy to save it in any format and move it into whatever other document you have.
Whereas some of the other ones are a little more challenging to do that or maybe don't have as high quality output as matplotlib does.
Especially if it's an SVG, you can scale that almost infinitely, right?
Yes, exactly.
Yeah.
Another thing that is going to be a repeated theme throughout many of these frameworks, but it's also here, is the ability, you know, not to just make one chart or one picture or one plot of some variation, but to build multiple plots.
Right.
So for example, a matplotlib, you can put, there's a, on the examples here, they have a MRI with EEG.
And so they've got the, the brain, a picture of the brain and then a MRI, and then also some other measurement, which I don't know enough brain science to know what it's for, but.
Neither do I.
It looks cool.
Right.
But you can, you can create a single picture that puts like two graphs and then a graph below it.
Right.
There's a way to compose these beyond just making one picture.
Exactly.
And if you think, well, I could do this in Excel, I could put two or three graphs next to each other.
But here's where the power of matplotlib comes into play.
Let's say you were running experience experiments in a lab and you're doing hundreds of these.
You wouldn't go into Excel and individually position all this.
No, you write your Python script.
You develop that layout for those different visualizations, and then you're done.
You know, once you get the data, you just kind of run through it and you can iterate through it.
And that's really the power using a real programming language, do visualization versus just trying to do one-off visualizations in Excel or some of the other tools out there.
Sure.
And instead of necessarily putting those pictures into a notebook output, you could write a loop.
It says, go get me this experiment's data and save, generate this graph and save it to a file.
Get the next one.
You know, find out even what's in the folder, pull them all in, loop over them, generate one picture, then the next, then the next, then the next with the right name.
And so it could just be all automatic, either in a script or just in a notebook that doesn't have as much output.
Right.
Exactly.
Yep.
The full power of Python is at your fingertips.
Yeah, absolutely.
All right.
So that's the kernel of one half of this branch.
Maybe the next one.
This one's a little bit surprising to me because I just don't do enough pandas.
But pandas, when I think about pandas, it's about manipulating data and reading data and transforming data and doing that tidy data preparation that you spoke about.
All those different things.
But there's also graphing built into pandas itself.
Yes.
And that graphing is built on top of Matplotlib.
So that's why from a course perspective and thinking about visualization, I think having that Matplotlib foundation sets you up so that when you're in pandas, where, like you said, you'll be doing the majority of your data input manipulation and analysis.
It's important to understand what visualization tools you have there.
And a lot of the standard visualizations that you want to do with a line chart, scatter plots, bar charts, box plots, histograms, you can do with pandas.
And it's mostly a very thin wrapper around Matplotlib.
So that's why it helps if you get this output and you look at it and say, well, I just want to customize it a little bit.
Typically, if you know that Matplotlib API, then you could customize it in pandas or go into Matplotlib and customize the pandas output.
So I think that is really useful.
The other thing that's interesting about pandas is it will allow you to plug in other backends.
So Matplotlib is the default, but you can enable backends for Plotly and a few of the other visualizations.
So it can be kind of this universal interface to visualization.
In my experience, I don't use the pandas visualization a whole lot, but I do think it's important for people to understand it's out there because there are times where that's the quickest way to get something out there.
And it's sufficient for the quick and dirty needs.
Well, yeah, sometimes you open up a panda, you read something like a CSV or whatever, and you just want to know, well, what is this?
And you would type DF for data frame, DF dot head or tail.
And it gives you just a little brief view into it.
There's the picture's worth a thousand words sort of thing.
And if all you have to say is just dot plot and that's it or dot hist.
And now you have a picture instead of that, that tail or head equivalent.
That's a really cool way to just sort of quickly explore the data.
Exactly.
And there are some other more unique plots in pandas.
So there are some plots called the Andrews curves and parallel coordinates that are more advanced.
And to be honest, you know, it's more of a data science kind of machine learning plot.
It's not something you use that often, but it is important to understand if you need it, that it is out there in pandas for you.
Yeah.
The Andrews curves reminds me a lot of like a Lorentz generator, a tractor.
Something from chaos theory.
A bunch of lines like looping over and over and over and over.
Exactly.
It looks pretty cool.
It does.
You'd probably blow some people's minds if you put that up.
But, you know, it's specialized.
But it does speak to there when you start getting into this visualization world, there are specialized libraries.
And you might find something in your niche that you're working that, you know, this is really useful and it's really powerful.
And it's maybe hard to do in other tools.
And boom, it's easy in pandas or some of the other tools.
Yeah.
So let me tell, I normally try to avoid saying code on here because it's audio, but given a data frame, I can say plot.figure and then just call Andrews curves, give it the data frame and a name and boom, you get this amazing visualization of your data.
Like on three incredibly simple lines.
Yes.
And this is the kind of stuff that I was referring to at the beginning when I said like, you almost don't need to know Python.
I mean, technically, there's a little bit of Python, but barely, right?
Right.
And it's just starting to understand how to think about how you could use these tools and getting familiar with it so that the first time you're trying to build something is not you're not also trying to learn in the API and all these other visualization topics on top of trying to solve whatever problem you're trying to solve with visualization.
Well, yeah, there's definitely some neat stuff to do visually with pandas and people should certainly be using it.
Also, based on the Matplotlib kernel, we have Seaborn.
Where does this fit into the world?
So Seaborn builds on top of Matplotlib, like you said, but it really focuses more on doing statistical analysis of your data and taking that data and frequently transforming it in some ways and developing a visualization.
So I use it a lot for histograms and box plots.
So I use it a lot for the time to see it a lot of people who have seen the data and see it a lot of people who have seen the data and see it a lot of people who have seen it in some ways.
So that's where you take a lot of people who have seen it in some ways.
And that's where you take a lot of people who have seen it in some ways.
So you have seen it in some ways.
So you've got nine, 12, you know, however many plots you need.
And it gives you an opportunity to spot data anomalies, trends very easily and present a wealth of information in a very compact frame.
And what I like about Seaborn is it is very easy to do this.
So the code that's required to do this is typically, you know, one or two lines of code.
And you get this really nice plot that has different colors.
It has data varying across the rows and columns.
You can change the shape, the size, everything to, you know, with those visualization concepts that we cover in the beginning to develop visualization that really give you a lot of insight very quickly.
Yeah, absolutely.
It's very statistical focused, isn't it?
It is.
You know, it is very statistical focused.
And some of the plots are more complex and having a statistical background will help you understand them.
But simple things like just doing bar plots or histograms or account plot or a heat map, you know, are relatively straightforward to explain to others and easy to create with Seaborn.
And then you're right.
There are some of the plots that are definitely much more kind of deep in the statistical toolbox.
And you have to know how you would explain them to others.
So this faceting thing is pretty interesting.
If you've got, if you go to the Seaborn examples, they've got one for looks like five different variables or sorry, four variables.
And they're looking at two different groups on one of them.
And you can just say, show me, you know, basically instead of give me a picture of this data, take any two pieces of information and generate a graph to show me how those things correlate.
One of the pieces of data that you did a lot of work with was the automobile gasoline efficiency data from the EPA, right?
Yes.
What I find really fascinating about this is when you get the data set up properly and you want to look at all these different relationships, it's very easy to slice and dice and mix up those relationships to see where the trends are.
So if we're looking at fuel efficiency, we could look at the year the cars were manufactured.
We could look at it by are they front wheel drive, all wheel drive cars?
How many cylinders do they have?
Are they electric?
SUV versus SUV?
All these things.
Yeah.
You know, there could be a price component.
There could be just a whole bunch of different ways to look at it.
And when you have a big data set, those are the types of things that are very difficult to do just by looking at the numbers.
And that's where visualization really shines.
And where Seaborn makes it tremendously easy to just quickly iterate through and say, okay, I want to look at these two variables together.
Now let's layer in a third variable.
Now there's a fourth variable.
Well, I don't like this.
Let's switch them around a different way.
And I use Seaborn a lot because of that flexibility of just exploring the data, quickly figuring out what those trends are, what those insights are, and rapidly iterating through it for the exploratory analysis.
Another thing that Seaborn has is it looks really nice and it has this idea of themes.
Yes.
So it's easy to make it look good, right?
It is.
I mean, Seaborn out of the box applies some themes and also does things behind the scenes with the visualization to make it cleaner and to try and format the data so that, you know, dates line up appropriately and colors look nice.
And there's appropriate spacing and things like that.
And there are some other things that are pretty easy to control to turn on and off or change the color palettes with Seaborn.
But generally out of the box, it strives to look good and it looks nice.
And what's also beneficial about it is it is just matplotlib under the hood.
And so if you get to the point where you've done your analysis and things look pretty good, but you want to do some tweaks, there are some convenience functions in Seaborn to do that.
But there's also, it's just matplotlib under the hood.
So if you know matplotlib and you want to tweak some things, you can do that as well.
Yeah, for sure.
One thing I want to maybe take a step back on here with matplotlib on a lot of these examples, not this one I got up here, but lots of them.
I'll see, and you talked about this, that we'll have like semicolons some of the time.
And, you know, Python's famous for not requiring semicolons at the end of lines.
What's the story there?
Yeah, the semicolons are just an artifact of when you're developing in a Jupyter notebook.
And when you show that plot, that matplotlib will show additional information about the plot.
So it will have kind of like a string descriptor, and then it will show the plot.
And if you use the semicolon, it will suppress that extra information.
So all you see is the plot.
So it's certainly, it's not required by any means.
And you're right, it does.
For people that have played with Python for a while, you kind of wonder why there's semicolon there.
But it's just to suppress some of that extra information that gets shown.
And it's not on all the lines.
It's just on certain plotting lines.
The other lines don't need it, right?
So it's a little unclear if you're not sure, which is why.
All right.
Moving on from Seaborn, we start to bridge our way over into the JavaScript D3JS side of things with Altair.
And Altair, I think, is certainly very well known.
Very well respected.
It's one of the newer ones, isn't it?
It is.
Yes.
I have to look.
I don't remember off the top of my head.
But if Matplotlib was started in like 2012, Altair is probably in the last five years or so.
Yeah.
I would imagine.
So definitely much newer, but has been tremendous amount of updates.
What was it?
2015.
Okay.
Yeah.
And Jake, who started it and maintains it, did an awesome job of leveraging a lot of the best practices from Python libraries as well as R to build Altair.
And like we said, it's built on top of Vega.
So there's that, you know, anytime that new work is done in that JavaScript library, it's easier to port it to Python so that you can leverage that as well.
Quite popular, almost 8,000 GitHub stars.
And Jake Vander Plaas added or changed 353,000 lines and removed 240,000 lines.
And Allison BG as well, something on a similar scale.
That's a ton of work.
Yeah.
It's a fabulous library.
I mean, there's one of the things I really like about the library is the gallery.
Yeah, that's where we're going now.
And the documentation is really great for Altair.
And once you start to get into it, you need to spend a little bit of time to just make sure you understand how the library works.
But then probably 90% of the time, you're going to go to the gallery and try and find something.
And you look at the code and you're like, oh, okay, that's how I do it.
Yeah.
Like, this is the one I want.
Yes, exactly.
There's a lot of interesting aspects about creating graphs here.
So one of the common ones is to create a scatter plot, which is called mark circle in this world, right?
And hopefully those are similar enough to be put together.
It's the same thing.
And those create little dots that show like, where's all the data from these different categories, say.
And one thing that's interesting is you can say, I'd like to color.
I want the X to be this value and the Y to be that value.
But then I want the color of the dot to be based on another column and maybe the size to be on a third one.
So in this EPA car data, you could say, well, I want the color of the dot to be the type of vehicle, like an SUV or a car or whatever.
And then I want the size to be the number of cylinders in the engine.
And that's just incredibly easy.
But it really draws out the data.
It does.
And Altair makes it easy to combine this in different ways.
So if you want to have a scatter plot and bar chart or a histogram, you can combine these together.
You can also do the faceting that we talked about with Seaborn.
You can do with Altair, where you change the variable across the columns and rows to get different plots.
And the other thing that Altair, one of the other things Altair introduces is interactivity out of the box.
So you, because it is JavaScript based, you then have that ability to go in.
And as you're doing here, for the people who can see it, you can hover over a spot and then control what information is shown for that hover.
So you can see, oh, what's going on with this individual dot?
Well, here's the, it's a Volkswagen Rabbit from Europe and it has a 71 horsepower engine and gets 31.9 miles per gallon.
And so it's really cool and really useful for doing that exploratory analysis where you kind of want to see the individual data points and maybe drill into it a little bit more.
Yeah, the interactivity is great.
The ability to add custom tooltips and then have those tooltips, have like F-string style formatting as well.
It's pretty excellent.
So if the data doesn't show up just the way you would like, you know, you can have something.
You can say small, medium, large versus like this number or that number.
So you can kind of think about it separately and differently, right?
Exactly.
And one of the other things that's interesting about Altair is it does try to infer different aspects about your data.
So it tries to understand, well, is this data continuous data?
Is it date data?
And you can specify the different types of data.
So you can say that it's quantitative or it's an ordinal value or nominal value.
And the actual visualization will change a little bit depending on that data type.
That's a unique thing that Altair does.
And I think that's one of those things that as you start going down this visualization path, you start to think about your data a little bit differently and think about how you want to present it.
And Altair gives you that window into all the flexibility you have with presenting data.
One of the really nice aspects of interactivity of these is the legend.
So the legend will show, you know, it really looks nice.
It matches like the color and the name and it's in a font that is pretty readable.
But if you set it up right, you can go and actually click on these and either just highlight one or you can have them sort of be toggle buttons.
And so if you want to just focus on, you know, let me pull out just in this case, it's got like agricultural finance, government type of spending or something.
You can just say, I want to just see the educational and health and click that and it highlights that sort of separate from the rest of them.
Yes.
And it's really easy.
There's like one line of code that you need to do to set that all up.
Add selection or something simple like that, right?
Exactly.
Yep.
One other thing I want to touch on with Altair here, and I also want to talk about an example, but you talked about, was it data?
Was it transforms or something?
You've got to either use the file or a little server or something to process the data.
What's the story of that?
Yeah.
So one of the things that can be a little tricky with Altair is behind the scenes, it's translating whatever data you have into a JSON file.
And so what that means is when you have 10 or 20 data elements, it's not that big a deal.
But when you have thousands of elements, you can suddenly get to a point where that file is really huge.
And so rightly so, Altair makes sure that you don't inadvertently embed that in your notebook.
So you could end up with your Jupyter notebook suddenly being, you know, 50 megs because you've got all these Altair visualizations in there.
So there are some options for how you can manage that data so that it's not necessarily stored directly in the notebook file.
Maybe you have that data stored separately, kind of like on a cache file in a directory or potentially more of like a real-time streaming option where you have a backend service that's running behind the scenes that streams up the data to you.
So there is a little bit more complexity sometimes with Altair to get it running.
And because of that visualization, because of the JSON approach that it uses.
So that's certainly one of the watchouts and things to keep in mind.
The other thing that sometimes has been a challenge for me with Altair is saving visualizations.
So if you want to create something as an SVG in Matplotlib or Seaborn, it's very straightforward.
You just save it.
With Altair, sometimes it can be a little challenging because of the way it's trying to render those visualizations and save them to a PNG or SVG file.
Yeah, so you've got to set that up and select the right one.
It'll work if you don't have too much data without doing that, right?
But then there's some limit where it's like, you know, this is too much.
You've got to have to push it outside of the notebook.
Yes.
You'll get an error message and it'll kind of tell you what's going on.
But I do mention it in the course, you know, some of the options for getting around it.
And the documentation is good about what those options are as well.
Sure.
All right.
So to wrap up Altair, I want to talk through a little example here.
And I'll put this example in the show notes so people can check it out.
Let's try to describe this picture here.
And like I said, I'll put it in the show notes so people can see it.
You have this Amazon author reviews for the top 20 most reviewed books,
most reviewed authors over the last 10 years or something like that, right?
Yes.
Tell us what's going on in this picture.
And we can maybe talk through just the API components that make it happen.
Sure.
So behind the scenes, the data is, I can't even remember, well, I guess this one's through
2016 or so, 10 years or so of Amazon reviews.
So on the X axis, it's 2009 through 2020.
And then on the Y axis, we have authors.
So a lot of famous authors in this timeframe.
And some of these authors will have one book a year.
They'll have multiple books a year.
And so it will have a circle where for each author for the year they published the book
and the size of the circle represents how many reviews they had.
So this is a really quick way to see how consistent some of these top authors are over years.
You know, it's sort of interesting, like Dale Carnegie is at the top.
I mean, he wrote this book, I don't know, probably 50 plus years ago, but it's still a bestseller
on Amazon.
And then you have other people that are maybe a little more sporadic, but it's a very easy
way to see the consistency and then the number of reviews that each author gets for a year.
And I would say, you know, if an author has more than one book, obviously they'll have more
reviews.
So it's not broken out by book.
It's just purely by author.
Right.
And when you build up this picture, some of the things that happen is there's a legend that
shows up.
The legend is basically just a copy slightly offset of what's on the left.
But what you really want to know is what's the size of the circle means.
So you can add like an alternative legend and you can put a grid behind it and make it
really easy to follow the timeline.
There's just a really cool bunch of features.
And this is the kind of picture I was thinking about when we were thinking, when I said, you
know, like if you just go and call plot or circle or whatever, you know, mark circle, you
end up with something that's not all that impressive.
But if you layer a few of these ideas on, then it's great.
We said we've got the author in the year and then the size, we configure the size based
on the number of reviews.
Then we configure the color based on the author so that it's a little easy to follow the
little easier visually to look at this and see the information.
And then we also do this thing that is interesting with Altair is when you think about Seaborn
and Matplotlib and Pandas and some of the other libraries we'll talk about, you typically do
the data manipulation in Pandas.
Altair has its own ability to do manipulation and transformation of data.
And so there is this option, you know, I could have filtered it down to the top 20 customers
or authors, excuse me.
But I use this transform filter to select only the top authors.
And that's all in Altair, not using any Pandas.
And then the final thing that we do is configure the width and the height and the title.
So that's all, you know, kind of one long piece of code that looks intimidating as you, you know,
maybe if you haven't worked with Altair.
But when you take a step back and break it down and think about what it is you're trying
to do with your visualization.
And then with the basic understanding of the Altair API, it's pretty straightforward and extremely
powerful.
Sure.
You kind of got to do it in steps.
It's a very fluent API, you know, Alt.chart.markcircle.encode.configure.
But if you take each one of those relatively simple function calls, then you try to understand
that and see what you're doing.
And then it turns out to be not too bad.
Yeah, exactly.
And what people need to realize when they're thinking about this course is anytime I develop
code and it looks like this and it has this many lines, you're right.
It wasn't, I didn't start off.
I did first, let's just do author versus year.
I don't like this.
I need to tweak one more thing.
Then I need to tweak one more thing.
And you iterate over it to get there.
And once you kind of understand how all these libraries work, it's not too much work, but
it does take a little bit of time.
And that's why it's important to, you know, dive into the data and play with it and experiment
with it and see what works for you.
Yeah, it almost is its own little mini language.
It is.
All right.
Before we move on to the next one, question from the audience.
I'm all out there.
Can we do responsive and animated workflow diagrams with matplotlib?
For example, continuous builds development on different server or deployment on different
servers?
Not entirely sure exactly what you're asking, but certainly you can automate these things,
right?
It doesn't have to be in a notebook.
This could all be put into a script, right?
Yes.
And there are matplotlib does support some animation.
And I can't remember how much of this is out of the box matplotlib versus third party libraries.
But I've certainly seen visualizations that people have done with matplotlib where it's, you know,
something changing over time or steps in a process.
You can do that with matplotlib.
So you could create one of those language battles.
Have you ever seen those where like over 20 or 30 years, it's either a browser or the language
is when the book is popular, then it goes up.
And yeah.
Yes.
Yeah.
You could do that.
I'd have to look and see what would be the best approach, but those sorts of options are
out there.
Fun.
All right.
Sticking in the JavaScript side of things, the other really popular one over there is Plotly.
What's special and unique about Plotly?
I think Plotly is special and unique because it is a newer plotting library, kind of on the
order of Altair.
It is supported by a company out of Canada, but the Plotly visualization library is completely
open source.
It is based on JavaScript.
What I like about it is everything is interactive out of the box.
So any plot you make, as soon as it renders, you can take your mouse and you can hover over
it.
You can zoom in.
You can limit the range of data.
And so that is really powerful.
And then the second thing that I really like about it is the history of Plotly.
There was a separate Plotly visualization.
And then there was something called Plotly Express, which was streamlined.
And the Plotly Express API, in my opinion, is very similar to Seaborn.
And it is very, I think it's Pythonic.
It's very easy to understand and pick up.
And over time, they've expanded it to where now that's kind of the default visualization.
So it's very easy to get started with Plotly.
It makes those interactive plots out of the gate.
And then it does have some unique plots.
So some of the kind of custom tree map plots, scatter matrix.
You can do plotting on maps to show geographic plots.
Those are all like out of the box, work pretty well and are fairly simple to create.
Yeah.
The tree map and the sunburst, those come from Plotly, right?
Yes.
At least are in Plotly is one of those things.
And one of the other things that is interesting about Plotly, like any of these visualization
tools, you have to be able to go in and configure and customize and tweak things.
And Plotly gives you that ability to generate a plot, but then you can update it over time.
So you can change colors.
You can change the way data is presented.
You can change pretty much anything with the plot using a fairly simple API as well.
Yeah.
People should definitely go and check out the tree maps example.
One of the really cool interactions is, for example, the one that I'm looking at here has,
here's the world and then here's the different continents.
So like Asia, Africa, the Americas.
Then if you want to, within each one of those, they've got a little box that says, well, here's
how large of an impact, like for example, Nigeria and Egypt are, you know, have more people
in it, I guess, than the other countries.
And then they're colored by what their actual values are.
But if you want to just focus on say Africa, you can just click on that section of this
thing and it just zooms in to show you just that information.
And this, you're not going to get this with Matt Plotlet.
No.
Right?
No.
No, you're not.
And it's...
The ability to just dive in and out of the data.
Yeah, absolutely.
And it is very simple.
I use Plotly quite a bit, especially when I want to explore the data.
So you want to have a scatterplot or this tree map or any of the other visualizations and you
can easily filter or zoom in, zoom out.
And yeah.
So you're showing some of the other cool kind of unique visualizations that are out there
to Plotly that maybe aren't as available in some of the other libraries.
Yeah.
The Sunburst has a real similar...
The Sunburst is like a pie chart, but as you interact with it, it like zooms into those
sections in pretty amazing ways.
Yeah.
Well, that is pretty cool.
I haven't actually seen that one.
That's neat.
It's just like...
Yeah.
It just draws...
It just says, I want to explore this data, right?
Not only can I, but like, I'm going to.
Yes, exactly.
Yeah.
Cool.
Does Plotly have this idea of like a backend server like Altair?
Plotly, out of the box, no.
It's more, I guess, you know, I have to think behind the scenes, the actual architecture.
I don't know, but I do know that you don't have to necessarily worry about your data as
much and suddenly having a huge file that shows up in your notebook that you have to deal with
Altair.
Yeah.
Amazing.
This is good looking stuff.
Yes.
And really top marks on the animation and interactivity, sort of diving into the data,
right?
Yes.
Yep.
Cool.
All right.
So that's the building block libraries for the different options.
I know there's many other plotting libraries and, you know, we saw in our original graph
that there's a bunch here that we didn't touch on, but, you know, these are the ones that
you felt are most important right now.
Yeah.
You know, it's interesting.
I struggled a little bit with where to draw the line.
You know, what else, some of the other things I might want to bring in after I posted about
the course, I did get some feedback, you know, how come we didn't talk about a bouquet and
panel and hollow viz.
And, you know, I think the short and sweet answer was I had to draw the line somewhere.
I didn't have as much experience with those libraries, so I didn't dive into them.
They are also libraries that are kind of undergoing some, they've undergone changes in the past and
they, they are working to clean up their documentation, get the examples cleaned up.
So I think it's certainly worth considering those as well.
The other one that I would point out that is really interesting to me, but I haven't used
it, but I think a lot of your listeners might be interested in is a library called Plot9 that
is meant for people that have used ggplot from an R perspective.
And it's essentially like a direct port of that to Python.
So if you really like ggplot and miss it from R, then you can use Plot9 to replicate
that in Python and it uses a matplotlib behind the scenes.
And it's, I mean, it looks fascinating to me, especially for people that come from that
R background.
Sure.
That's something we haven't even touched on is like the influence of R and like the parallels
there.
And, and...
Yes.
We probably want too much.
So we've got two more things to cover and these are...
How do I maybe run my code?
If I want to put it online and make it interactive and let other people interact with it.
Right?
So two of them, Streamlit and Plotly Dash.
Tell us about these.
Yes.
So, you know, everything we've talked about now there, especially with Plotly and Altair,
there is some degree of interactivity.
But when you want to build a dashboard or want to build more of like an application where
you can select and filter data, maybe have different visualizations, maybe have complex visualizations
like, like maps.
You need something more than just the out of the box Altair or Plotly.
And Streamlit is a very simple way to wrap a little bit of extra Python code around your
visualization and you get this interactive application for free.
And so like the demo you're showing right now is a great, you know, really powerful example
that shows Uber ride sharing in New York City.
It has sliders for you to choose what time the pickup happens.
And then it has these real time visualizations for different parts of the city about how
many pickups are happening.
And what's so cool about Streamlit is there is very little additional Python code you need
to do that.
So the workflow that I will typically do is I'll do my visualizations in Seaborn or Plotly
or Altair.
And then once I realize I need that next level, I can then just easily plop them into a separate
file with a couple lines of Streamlit code.
And boom, I've got an interactive application that I can run.
Yeah.
It's a really interesting way of programming.
You basically write a top to bottom procedural script that says, if I, in this case, what are
we, we're putting, we're putting the hour of a pickup, the hour of data you want to slice
and visualize.
And you said, well, if I could write a function that would make a graph given the hour, then
you just say, and make the web app.
You know what I mean?
And it gives you the interactive sliders for all the variables that go in.
And then you just, as the slider changes, it just recalls your functions.
And you don't have to know anything about web programming or AJAX or front end code.
And all of that just happens.
It's, it's pretty fantastic.
Streamlit was recently acquired, I think so recently, but within a year or two.
Yeah, they're acquired by Snowflake for a really large amount of money.
I know a lot of people are kind of scratching their head at that valuation, not to knock on
Streamlit.
I mean, congrats to them, but it's really interesting tool.
And it will be interesting to see what Snowflake does with them.
But you know, this tool right now is open source.
And I do think it is a very powerful, easy way to get a real web native interactive app with
very little code.
Yeah, absolutely.
Let's see.
Demetrius out there has a question, says, there are all these ways to make graphs quickly,
but I can't find anywhere on how, any information on how to make an interactive calendar with
events quickly.
Yeah, that's a good question.
I don't know.
Yeah, I don't know either.
Of any of these plots that have like a calendar function.
You don't possibly Streamlit.
It might.
Maybe.
It's interesting that you bring up Streamlit because Streamlit does have like third
party apps or plugins that you can incorporate.
that the individual opposed to that.
I definitely encourage them to take a look at Streamlit and see if there's something out
there.
So I interviewed, I believe it was Adrian.
Let me double check.
Yeah.
Adrian Truel back early days, early days of Streamlit.
I mean, we're talking two years ago before it was acquired about that.
So people can check that out.
And I'm somewhat familiar with that.
The other one, though, that's very fascinating that I don't know about is Dash.
How's that compared to Streamlit?
What's the, this comes from the Plotly company as well.
Yes.
So Plotly, like we mentioned, is a company.
They have Dash, which is a much more sophisticated and in-depth platform for developing interactive
applications or dashboards.
So whereas Streamlit is a little bit of code, Dash is much more of you kind of are embracing
HTML and CSS and you're doing callbacks and you have just a ton of flexibility in how you
structure your application.
And like this, this demo you're having here, you've got wind speed histograms and you've
got a line chart that's fully interactive and interactivity between the charts.
As you choose one, it influences another.
You can, Dash gives you flexibility to kind of manage the backend as well.
So you can run it.
I think it's, it's a Flask server, like on your system, you could do that.
But if you wanted to do an enterprise grade deployment, you could do that as well.
It's really, if you can think of it, Dash will probably let you do it.
And if you're a big enough company and it's mission critical, Dash does have that enterprise
support where you can pay a company to host it and support it for you.
You can build, if you, people should go look at the gallery for Plotly Dash.
There's a bunch of interesting things.
And one of the areas that stands out, I mean, you've got many, many different types of visualizations
and whatnot.
But one of the things that stands out for me is the streaming, streaming data aspect,
you know, create a dashboard where you hook it up to stock market data or IOT data and
it just goes, right?
Right.
Exactly.
It's designed to, you know, support a lot of data and low latency and all those kinds
of things.
So it's, it's really powerful, but this is one of those areas we talked about everything up
until now.
You don't really have to know a whole lot of Python.
Once you start getting into building Dash, it gets a little more complicated.
And I think that's where you want to make sure you've got a good solid Python foundation
before you go and build a dashboard to run your company.
Yeah.
But it's very powerful.
Very powerful.
Yeah.
The interactivity between the different elements is also quite interesting.
It is.
Yes.
And that's one of the, I mean, you can do that to some degree with Streamlit, but Dash just
makes, yeah, you can have a ton of interactivity between the different widgets and the different
visualizations.
Cool.
Well, it looks great.
If I had a dashboard that looked like this, I'd be proud of it.
It's not one of those things that's just like, oh, I guess I, I guess it works.
You know, no, it looks great.
Yeah.
I would be too.
Yeah.
Cool.
All right, Chris, we spent a lot of time on, on this.
I think we should probably button it up, but.
Yeah.
Bring it home.
A lot of great stuff.
Yeah.
A lot of great stuff in the visualization library space.
I think that's one of the really very powerful aspects of Python is it's just all of these
tools.
It's not the language.
It's not the standard library, which all those, they are important.
Like it's, people need to think this is sort of what people are talking about when they
say Python's awesome.
It's great to use.
It's not how it does a for loop.
It's that I can say, you know, dot Andrew's curve.
Yes.
Yeah.
And it all builds, right?
So if you're, you know, just starting on Python, then you start to build a little pandas
knowledge.
You don't have to throw that away and then focus on visualization.
It all builds on top of it and you can leverage all that knowledge and then all the other wonderful
libraries that are out there.
Absolutely.
All right.
Before you get out of here though, final two questions.
If you're going to write some Python code, what editor or editors do you use?
I'm pretty much a hundred percent VS Code now.
Right on.
Even over notebooks.
Yes.
I've gotten to where I use the native VS Code notebooks and I really like that.
Like the comment divider type of style.
It's just, they, they have continued to update it so much that it just seems like it's a superior
approach for what I do and how I manage my environments right now.
Nice.
And then notable PyPI package or as.
Yeah.
I put two in here.
I don't have a ton of experience with them, but I wanted to call them out because I do
want to spend some time with it.
So the first one is Splink.
I wrote an article a couple of years back about doing data linkage or data duplication.
And so for, for those of you that aren't familiar, it could be a situation where let's say you
have your customer database and it's got Chris Moffitt lives at one, two, three main street
and you have a third party data set.
And it says, Mr. Moffitt lives at one, two, five main street and street is spelled a street.
How do you merge all that data together?
How do you do fuzzy matching?
And I played around with different options.
And this Splink is one that's actually came out of the UK from an individual that works
at the Ministry of Justice, which I think is just a cool name.
And he talks about using this to, to merge, you know, millions of records together.
And I think it's a kind of really interesting tool that is something that you can't really
do in Excel and it's a challenging problem.
And anytime someone's spent some time on that kind of problem, I think it's really interesting
and I want to spend some more time looking at that.
Yeah.
And they have on that GitHub repo, they got a couple of videos introducing it, which is great.
Yes.
And the other one.
Red frames.
So this is another one that I've seen come across my Twitter feed a couple of times.
I have not used it directly, but it is another library for manipulating data that's interoperable
with pandas, but gives a little bit more of that fluent API where you can kind of string
all these commands together to modify your data in ways that pandas supports a lot of this,
but there are certainly some things in pandas that are a little bit clunky.
And this looks like it's an attempt to try and bring some of that R goodness to Python.
Yeah.
It also looks a little bit like bringing SQL to it.
Yes.
Yeah.
Certainly there's.
A filter, a group, a sort, you know, change the names a little bit.
Yeah.
Filter away or sort order by, you know, it looks a little bit like SQL.
It just looks really interesting.
And like I said, I wanted to get some visibility to it and I haven't used it extensively, but
certainly want to play around with it a little bit more.
I thought your listeners might be interested.
Yeah.
It looks very cool.
Thanks for sharing that.
All right.
People are interested in Python data visualization.
They want to know more.
What do you tell them?
Hey, check out the course.
So really excited about the course.
If you've liked what you've listened to here, the course on Talk Python training has the examples,
the notebooks for you to go through and learn and play with this on your own.
And by the end of it, you should be at the point where you can start to apply it to your
own data.
So encourage you to check it out.
And if you do check it out, let me know.
Be interested to see what you think.
Yeah.
It definitely covers all of this in hands-on detail, not just conceptually.
So yeah.
Thanks for being here, Chris.
Thanks for sharing your experience.
And yeah.
Happy to have you back on the show.
Thank you.
Great discussion.
Yeah, you bet.
Bye-bye.
Bye.
This has been another episode of Talk Python to Me.
Thank you to our sponsors.
Be sure to check out what they're offering.
It really helps support the show.
Starting a business is hard.
Microsoft for Startups, Founders Hub provides all founders at any stage with free resources
and connections to solve startup challenges.
Apply for free today at talkpython.fm/founders hub.
Want to level up your Python?
We have one of the largest catalogs of Python video courses over at Talk Python.
Our content ranges from true beginners to deeply advanced topics like memory and async.
And best of all, there's not a subscription in sight.
Check it out for yourself at training.talkpython.fm.
Be sure to subscribe to the show.
Open your favorite podcast app and search for Python.
We should be right at the top.
You can also find the iTunes feed at /itunes, the Google Play feed at /play,
and the direct RSS feed at /rss on talkpython.fm.
We're live streaming most of our recordings these days.
If you want to be part of the show and have your comments featured on the air,
be sure to subscribe to our YouTube channel at talkpython.fm/youtube.
This is your host, Michael Kennedy.
Thanks so much for listening.
I really appreciate it.
Now get out there and write some Python code.
I'll see you next time.
Thank you.