Chart Type - Number Overlays with Secondary Reference Number

 Contextualizing KPIs is a must. For instance, if a company has 500 users, how does that compare to the number of users last week? Using Periscope Data's Python Integration, we can create customized number overlays to cleanly present this information.

To create the visualization above, we assume that our SQL output generates 1 row of data with 2 columns:

  1. Our KPI. in this case, number of users
  2. The percent change (for proper formatting, use Periscope's percent formatter shortcut :%)

Then, we apply the following Python 3.6 code on the SQL output. Here we are also adding some helpful text to describe the KPI and adding some arrows and coloring to contextualize the KPI.

import pandas as pd
import matplotlib.pyplot as plt

fig = plt.figure()

plt.gcf().set_size_inches(8, 2)


plt.text(.5, .95, 'New Users', fontsize=25, color='black', ha='center')
plt.text(.5, .75, 'This Week', fontsize=12, color='black', ha='center')
plt.text(.5, .25, str(df.iat[0,0]), fontsize=50, color='black', ha='center')
plt.text(.5, 0, dir + ' ' + val +' from prior week', fontsize=15, color=col, ha='center')


How does your business like to format KPIs in Number Overlays? Comment below!

5replies Oldest first
  • Oldest first
  • Newest first
  • Active threads
  • Popular
  • Timely solution, I was just looking for a solution like this.  Hopefully it gets added to the standard overlay.

    Reply Like 2
  • What are you using to return the arrow?   I can make something similar symbol using unicode.    

    Something like this (which also works coming from the sql)

    plt.text(.5, 0, u'\u2193 '+pc + ' to goal', fontsize=15, color=df.iat[0,2], ha='center')

    Works fine for me, just wondering if there was another way.

    Reply Like
      • Neha Kumar
      • Solutions Engineer
      • Neha_Kumar
      • 1 yr ago
      • Reported - view

      Ron Johnson Apologies for the delay here! Earlier I was pasting the unicode character into the SQL editor, however I updated the Python snippet to do the unicode encoding for us 

      Reply Like
  • Thank you Neha Kumar , this is really useful.

    A question: How do you control the whitespace around the plot when it renders on the dashboard?

    I can create a plot that looks good in the 'edit' screen, but shrinks a lot when it appears on the dashboard.

    Reply Like
      • Neha Kumar
      • Solutions Engineer
      • Neha_Kumar
      • 7 mths ago
      • Reported - view

      Conor OKane Great question, you may need to resize/scale the figure in that case. Details on how to do that here, let me know if that works for you!

      Reply Like
Like1 Follow
  • 7 mths agoLast active
  • 5Replies
  • 1482Views
  • 4 Following