Slopegraphs in Python – Slope Colors

As the codebase gets closer to the 1.0 stretch we now have the addition of slope colors for when values go up/down or remain constant between points. The code still only handles two columns of data, but the intent is for each segment to also be colored appropriately (up/down/same) in a multi-column layout.

I was scanning for ‘slopegraph’ again via a few search engines and came across Chris Conley’s (@ResearchChat) Education and Health Care – Using Slopegraphs to Understand Complex Systems. I really like what Chris has done with the slopegraph formatting and copied the LINH data example to the project. As you can see, Chris came up with a pretty neat way to handle the overlapping data/label issue (and one which I may “borrow” when expanding my slopegraph generator):

Since Chris used colors, it seemed like a fitting example to use to show off the newest feature of the slopegraph code. Here’s the output for the same data with my implementation.

Both “slope_up_color” & “slope_down_color” (Lines 23-24) control the slope color.

This example also showed that the ‘header’ processing needs some tweaking. The code currently assumes the header label width will be less than or equal to the width of the data labels. We’ll need to do some bounding box fitting and/or canvas expansion to enable more robust header text formatting.

Given the minor tweak, no code inclusion here but yet-another handy link to github.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
{
 
"label_font_family" : "Arial Narrow",
"label_font_size" : "9",
 
"header_font_family" : "Arial Narrow",
"header_font_size" : "10",
 
"x_margin" : "20",
"y_margin" : "30",
 
"line_width" : "1.0",
 
"slope_length" : "300",
 
"labels" : [ "# Below Average Indicators", "# Above Average Indicators" ],
 
"header_color" : "000000",
"background_color" : "FFFFFF",
"label_color" : "111111",
"value_color" : "999999",
"slope_color" : "222222",
"slope_up_color" : "B0B465",
"slope_down_color" : "A13E52",
 
"value_format_string" : "%2d",
 
"input" : "examples/linh.csv",
"output" : "examples/output/linh",
"format" : "pdf",
 
"description" : "2011 report from ICES; LINH Indicators",
"source" : "http://cconley.ca/2011/07/18/education-and-health-care-using-slopegraphs-to-understand-complex-systems/"
 
}
Cover image from Data-Driven Security
Amazon Author Page

1 Comment Slopegraphs in Python – Slope Colors

  1. Chris Conley

    Great implementation in Python! In another implementation of this approach I used transparencies on the slopes to draw the eye across to the highest value in the slope.

    Reply

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.