Plotting campaign results (I)

1. Plotting campaign results (I)

Now that you've practiced aggregating and segmenting the results, it's time to learn how best to visualize these results in order to increase ease of interpretability, especially for people on our team who might be less comfortable with data.

2. Comparing language conversion rates

Let's use the language_conversion_rate series you created in the previous lesson. First, we'll import matplotlib's pyplot module as plt. Next, we call the plot() method on language_conversion_rate and specify the kind argument as bar indicating that we want to create a bar chart. Bar charts enable us to visually compare the conversion rates. Next, we add a title and axis labels to this plot. Finally, we show the plot using plt dot show().

3. Retention by language chart

And here's our plot! As we saw in the last lesson, Arabic and German have the highest conversion rates. However, instead of looking at a bunch of numbers, you can now quickly interpret the results by looking at the plot.

4. Calculating subscriber quality

In the previous lesson, we looked at how subscriber quality varied over time by looking at retention rates for each day. This was the code you used to calculate the daily retention rate. When looking at retention rates over time based on when users subscribed, we are doing a simple form of cohort analysis that helps us evaluate the quality of subscribers we're bringing in each day. If we see this metric trend up over time, that could mean we're getting better at converting users who are genuinely interested in our product or that we're improving our onboarding process once users subscribe.

5. Preparing data to be plotted over time

Before we plot this data, let's first convert the pandas series into a DataFrame by calling the reset_index() method on the series and wrapping the output in a call to pd dot DataFrame. Then we rename the columns using the columns attribute. Make sure you provide column names in the correct order and that there's a label for every column.

6. Visualizing data trended over time

Again, we call the plot() method on the daily_retention_rate DataFrame and pass the x and y arguments, that is, date_subscribed and retention_rate, respectively. Next, we add a title and x and y labels like in the previous chart. One thing to remember here is that matplotlib tries to be smart about the scale of the axes by rescaling it from the lowest to the highest values. While this is useful for dates on the x-axis, it has a negative side-effect for the values on the y-axis. The plot would show misleadingly large spikes in retention rates due to the range of the y-axis. Therefore, we use the ylim() function to explicitly set the y-axis to begin at 0.

7. Daily subscriber quality chart

And here's our final plot showing how subscriber quality changed over time.

8. Let's practice!

As you can imagine, there are endless ways to customize your charts to be more useful, interactive, and aesthetically pleasing. I encourage you to check out other plotting resources if this topic interests you. Now, let's practice!