An Algorithm for Creating and Selecting Graph Axes

For an arbitrary set of data points, what’s the ‘best’ graph axis for those points? Say that your x-variable runs from 5 to 45. A human can quickly pick a few promising options for the x-axis. It could have ticks at 0, 15, 30, and 45. Or perhaps 0, 10, 20, 30, 40, and 50. Getting a program to generate ‘nice’ options like this is a bit trickier. I’ve been working on a graphing app recently and I’ve reproduced my solution, with notes, below.

graph_axes

Although there are a number of algorithms people have put forth on Stack Overflow and elsewhere, many of these do not handle certain kinds of data sets correctly, and virtually none treat 0 correctly in my opinion. I started from scratch with the following 5 rules for my function:

  • If an axis crosses 0, 0 *must* be an axis tick value
  • Axis ticks *must* be attached to a grid line (i.e. you can’t have x-axis ticks floating in space – they must be attached to a y-axis grid line as you see in the example above)
  • The data should be as tightly contained as possible (little wasted space)
  • There should be no fewer than 4 ticks on each axis, and if rule 2 requires it, up to 10
  • Numbers should be ‘nice’ (round numbers etc.)

Continue reading

Scaling and displaying Adjusted Defensive Impact

I rigged up a convenient tool for displaying my adjusted defensive impact graphs. The graphs are drawn as SVGs, and the code is all written to produce graphs that are 750 pixels wide. Unfortunately that has meant that when someone else wants to display a graph (or if I want to use it in a different context), the graphs resize poorly.

So I kluged together a little API of sorts that will draw them at any width you like. Unfortunately I’m still having trouble converting them to PNGs, so you’ll still have to take screen caps of graphs you want to display, but at least it will look right now.

So how do you do it? Just adjust the values in the URL below. The ‘width’ parameter can be changed to anything at all (although it will probably look a bit weird under 500 pixels or so), and just input a player’s full name for the player parameter. Make sure you capitalize the first and last and put %20 between the names. The example below and its associated graph is shown.

http://www.austinclemens.com/blog/data/adicl3.html?width=550&player=Taj%20Gibson

Taj Gibson

Roy Hibbert and the fundamental interconnectedness of all things

Hibbert in gameThis post is about the amazing Roy Hibbert. It has been a long time since my last post because I have been writing a tool for collecting and analyzing NBA game data. The first fruit of that effort is the two graphs below. Before I get to them, I have to explain why I thought any of this was worth doing in the first place.

NBA observers are always talking about how some player makes everyone around him better. This sports cliche is almost always used in basketball to talk about point guards or a combo/wing player with good court vision in the mold of Kobe or LeBron. The ‘makes his teammates better’ meme is actually particularly apt for describing basketball. Sure, a quarterback and a receiver need each other, and a quarterback needs his offensive line. And yeah, one bad fielder can ruin a good double play. But teammates in these sports are not as reliant on each other as the five players on a basketball court are.

Continue reading