Understanding What Declarative Charts Are
00:00 Before we dig into the specifics of the Altair library, let’s take a detour and understand what declarative charts mean to understand how Altair has a different approach to visualization than something like Matplotlib.
00:12 When you visualize data with Matplotlib, it uses a method that we would call imperative. This means that you build the plot piece by piece by issuing drawing commands.
00:23 You’re fully in charge of creating every little aspect of the chart. Sometimes this is the right approach. With Altair, however, your focus is always on the output visualization.
00:35 Your focus is on the data and what the final visual looks like, and Altair handles all the drawing under the hood. If you don’t want to control every little aspect of your visualization, this declarative approach is helpful in reducing the amount of code you need to write.
00:51 You declare your output, what the visual should look like, not how it should be made, not the steps that are required to create that visual. Let’s contrast a couple of small code examples to see the difference.
01:05 In Matplotlib, you typically start by creating a figure and an axis object. Both of these hold information about the final visual. You would then plot some data onto the axis and then take that axis object and control every little element of it.
01:21 You can set the title, the labels, all the different formatting options, and so on. So you’re fully in control by having those figure and axis objects to hand.
01:31 It does, however, mean you need to think about every little element of the chart and specify each of those details. In contrast, with Altair, as you’ll see, you still need to create a chart object, but then your focus will shift towards the final visual.
01:47 What kind of visual elements does it need? Points, lines, shapes, and so on. And how does the data map to the visual elements? You won’t be issuing individual draw commands to control every single element of the final visualization.
02:02 Now that we’ve briefly discussed the difference between Altair’s declarative approach and Matplotlib’s imperative approach, it’s time to start coding. In the next lesson, you’ll start by installing the Altair library.
Become a Member to join the conversation.