.. _graphics-anchor: 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 :ref:`group-anchor`) 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 :ref:`basic-anchor`). The additional requirement for scatter plots is that the first two request parameters are numbers (see :ref:`parameter-anchor`). 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 :ref:`group-anchor`). 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 :ref:`summative-anchor`). 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 :ref:`basic-anchor`). The additional requirement for bar charts is that the first parameter is an integer (see :ref:`parameter-anchor`). 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 :ref:`basic-anchor`). The additional requirements for box charts are that the first parameter is a number (see :ref:`parameter-anchor`) and that the conditions generate an endogenous grouping (see :ref:`group-anchor`). 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