Graphics¶
The Sports Data Query Language is a data-visualization aware query language. A few SDQL characters produce informative scatter plots, bar charts, and box plots. SDQL’s grouping queries (see Grouping) generate small multiples of these graphics.
scatter: x,y@conditions¶
The basic structure of the SDQL for graphics is the same as for text output (see Query Structures). The additional requirement for scatter plots is that the first two request parameters are numbers (see Parameter Types).
- To build a scatter plot with team’s points on the horizontal axis and opponent’s points on the vertical axis for each NBA game in 2016, use the SDQL:
- points, o:points @ season = 2016
A separate graphic is made for each group in the first conditional term.
- To make a separate scatter plot of o:points vs. t:points for each NBA team in 2016, use the SDQL:
- t:points, o:points @ team and season = 2016
Groupings in higher conditional terms produce color-coded markers.
- To make a single scatter plot of o:points vs. points with NBA teams color-coded, use the SDQL:
- t:points, o:points @ season = 2016 and team
A single scatter plot is returned because the first condition is a singleton (season=2016). Teams are color-coded within the scatter plot because of the implicit grouping in the second condition (see Grouping).
scatter: x,y,icon@conditions¶
A third request parameter indicates the icon to use in the scatter plot.
- To build a scatter plot for points vs date for the 2016 playoffs with team icons, use the SDQL:
- date, points, team @ season = 2016 and playoffs=1
- To see the winning percentage vs date for MLB teams in 2017 use the SDQL:
- date, 100*A(W), team @ season=2016 and team?marker_size=20
The third request parameter team invokes the use of team logos as plot icons. The Average is turned into a moving-Average with the use of 100* on the outside of the Summative (see Summative). The use of A(100*W) would return an irregular data table unsuitable for a scatter plot.
bar: x@conditions¶
The basic structure of the SDQL for graphics is the same as for text output (see Query Structures). The additional requirement for bar charts is that the first parameter is an integer (see Parameter Types).
- To see the number of occurrences of each final margin in 2016 NBA games, use the SDQL:
- margin @ season=2016
bar: x,label@conditions¶
An optional second request parameter for bar charts can be used to label the vertical axis.
- To see the distribution of MLB starter-innings pitched in 2017,use the SDQL:
- int(Starter:innings pitched*3) as ‘Outs by Starter’,’Number of Games’ @ season=2017
When the SDQL conditions contain a grouping, small multiples are generated.
- To see the distribution of MLB starter-innings pitched in 2017 for each team,use the SDQL:
- int(Starter:innings pitched*3) as ‘Outs by Starter’,’Number of Games’ @ team and season=2017
box: x@groups¶
The basic structure of the SDQL for graphics is the same as for text output (see Query Structures). The additional requirements for box charts are that the first parameter is a number (see Parameter Types) and that the conditions generate an endogenous grouping (see Grouping).
- To see a box plot of points for NBA teams in 2016, use the SDQL:
- points @ season=2016 and team
?arguments¶
SDQL queries take optional arguments instantiated with a question mark and delimited with an ampersand.
- To see a box plot of points for the top 40 NBA player in 2016, use the SDQL:
- points @ season=2016 and name?show=40
- To generate scatter plots of cumulative points for each player on each NBA team in 2016, use the SDQL:
- date, 1*S(points) as Points @ team and name and (season=2016) as ‘Points v Date for NBA Players in 2016’?legend_show=0&marker_size=1&xticks=-1
The first condition team generates exogenous groups and the second condition name generates endogenous groups. That is, there is a separate scatter plot for each team and each player gets a color.
Common graphical options include:
- marker_size
- symmetric
- xsymmetric
- ysymmetric
- xticks
- yticks
- xtitle
- title
- ytitle
- show
- xmax
- xmin
- ymax
- ymin
Bar chart specific options include:
- linewidth
- histtype
- stacked
- histwidth
Scatter plot specific options include
- pearson
- polyfit
- polyfit_show
- polyfit_sort
- polyfit_linewidth
- polyfit_error_scale