  
  [1X2 [33X[0;0YUsing the high-level API[133X[101X
  
  
  [1X2.1 [33X[0;0YCharts and Plots[133X[101X
  
  [33X[0;0YThis  section  covers the [2XPlot[102X ([14X7.1-1[114X) function in the high-level API, which
  is  used  for showing charts and plots. If invoked in a Jupyter Notebook, it
  will  show the resulting visualization in the appropriate output cell of the
  notebook.  If  invoked  from  the  [5XGAP[105X  command line, it will use the system
  default web browser to show the resulting visualization, from which the user
  can  save a permanent copy, print it, etc. This section covers that function
  through  a  series of examples, but you can see full details in the function
  reference in Chapter [14X7[114X.[133X
  
  [33X[0;0YTo  plot  a  list  of numbers as a single data series, just pass the list to
  [2XPlot[102X ([14X7.1-1[114X).[133X
  
  [4X[32X  Example  [32X[104X
    [4X[28XPlot( [ 6.2, 0.3, 9.1, 8.8 ] );[128X[104X
  [4X[32X[104X
  
  [33X[0;0YResulting image not shown here.[133X
  
  [33X[0;0YNotice that the default [23Xx[123X values for the data are the sequence [10X[1..n][110X, where
  [23Xn[123X is the length of the data. You can specify the [23Xx[123X values manually, like so:[133X
  
  [4X[32X  Example  [32X[104X
    [4X[28XPlot( [ 1 .. 4 ], [ 6.2, 0.3, 9.1, 8.8 ] );[128X[104X
  [4X[32X[104X
  
  [33X[0;0YThis  is  useful  if  you  have a scatter plot of data to make, or if your [23Xx[123X
  values are not numbers at all.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[28XPlot( [ "Mon", "Tue", "Wed", "Thu" ], [ 6.2, 0.3, 9.1, 8.8 ] );[128X[104X
  [4X[32X[104X
  
  [33X[0;0YResulting image not shown here.[133X
  
  [33X[0;0YIt  is also permissible to send in a list of [23X(x,y)[123X pairs rather than placing
  the [23Xx[123Xs and [23Xy[123Xs in separate lists. This would do the same as the previous:[133X
  
  [4X[32X  Example  [32X[104X
    [4X[28XPlot( [ [ "Mon", 6.2 ], [ "Tue", 0.3 ], [ "Wed", 9.1 ], [ "Thu", 8.8 ] ] );[128X[104X
  [4X[32X[104X
  
  [33X[0;0YYou can also pass a single-variable numeric function to have it plotted.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[28XPlot( x -> x^0.5 );[128X[104X
  [4X[32X[104X
  
  [33X[0;0YResulting image not shown here.[133X
  
  [33X[0;0YIt  assumes  a small domain of positive integers, which you can customize as
  follows.  Note  that the [23Xx[123X values are passed just as before, but in place of
  the [23Xy[123X values, we pass the function that computes them.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[28XPlot( [1..50], NrSmallGroups );[128X[104X
  [4X[32X[104X
  
  [33X[0;0YResulting image not shown here.[133X
  
  [33X[0;0YYou  can  append  a  final  parameter  to the [2XPlot[102X ([14X7.1-1[114X) command, a record
  containing a set of options. Here is an example of using that options record
  to choose the visualization tool, title, and axis labels. Section [14X2.2[114X covers
  options in detail; this is only a preview.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[28XPlot( [1..50], n -> Length( DivisorsInt( n ) ),[128X[104X
    [4X[28X      rec([128X[104X
    [4X[28X          tool := "chartjs",[128X[104X
    [4X[28X          title := "Number of divisors of some small integers",[128X[104X
    [4X[28X          xaxis := "n",[128X[104X
    [4X[28X          yaxis := "number of divisors of n"[128X[104X
    [4X[28X      )[128X[104X
    [4X[28X);[128X[104X
  [4X[32X[104X
  
  [33X[0;0YResulting image not shown here.[133X
  
  [33X[0;0YYou can also put multiple data series (or functions) on the same plot. Let's
  pretend you wanted to compare the number of divisors of [23Xn[123X with the number of
  groups of order [23Xn[123X for the first 50 positive integers [23Xn[123X.[133X
  
  [33X[0;0YTo do so, take each call you would make to [2XPlot[102X ([14X7.1-1[114X) to make the separate
  plots,  and place those arguments in a list. Pass both lists to [2XPlot[102X ([14X7.1-1[114X)
  to  combine  the  plots,  as  shown below. You can put the options record in
  either  list.  Options  specified  earlier  take  precedence  if  there's  a
  conflict.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[28X# We're combining Plot( [1..50], NrSmallGroups );[128X[104X
    [4X[28X# with Plot( [1..50], n -> Length( DivisorsInt( n ) ) );[128X[104X
    [4X[28X# and adding some options:[128X[104X
    [4X[28XPlot([128X[104X
    [4X[28X    [ [1..50], NrSmallGroups,[128X[104X
    [4X[28X      rec( title := "Comparison", tool := "anychart" ) ],[128X[104X
    [4X[28X    [ [1..50], n -> Length( DivisorsInt( n ) ) ][128X[104X
    [4X[28X);[128X[104X
  [4X[32X[104X
  
  [33X[0;0YResulting image not shown here.[133X
  
  [33X[0;0YThe  default  plot  type  is  "line", as you've been seeing in the preceding
  examples.  You can also choose "bar", "column", "pie", and others. Let's use
  a pie chart to show the relative sizes of the conjugacy classes in a group.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[28XG := Group( (1,2,3,4,5,6,7), (1,2) );;[128X[104X
    [4X[28XCCs := List( ConjugacyClasses( G ), Set );;[128X[104X
    [4X[28XPlot([128X[104X
    [4X[28X    # x values are class labels; we'll use the first element in the class[128X[104X
    [4X[28X    List( CCs, C -> PrintString( C[1] ) ),[128X[104X
    [4X[28X    # y values are class sizes; these determine the size of pie slices[128X[104X
    [4X[28X    List( CCs, Length ),[128X[104X
    [4X[28X    # ask for a pie chart with enough height that we can read the legend[128X[104X
    [4X[28X    rec( type := "pie", height := 500 )[128X[104X
    [4X[28X);[128X[104X
  [4X[32X[104X
  
  [33X[0;0YResulting image not shown here.[133X
  
  
  [1X2.2 [33X[0;0YOptions for charts and plots[133X[101X
  
  [33X[0;0YThe  options record passed as the final parameter to [2XPlot[102X ([14X7.1-1[114X) (or as the
  final  element  in  each  list  passed  to [2XPlot[102X ([14X7.1-1[114X), if you are plotting
  multiple series on the same plot) can have the following entries.[133X
  
  [30X    [33X[0;6Y[10Xtool[110X  -  the  visualization tool to use to make the plot, as a string.
        The  default  is  "plotly".  The  full  list  of tools is available in
        Section [14X1.2[114X.[133X
  
  [30X    [33X[0;6Y[10Xtype[110X  -  the  type  of  chart,  as  a string, the default for which is
        "line". Which types are available depends on which tool you are using,
        though  it  is safe to assume that most common chart types (line, bar,
        pie)  are  supported  by  all tools. Section [14X3.4[114X contains links to the
        documentation  for  each  tool, so that you might see its full list of
        capabilities.[133X
  
  [30X    [33X[0;6Y[10Xheight[110X  -  the  height  in  pixels  of the visualization to produce. A
        sensible default is provided, which varies by tool.[133X
  
  [30X    [33X[0;6Y[10Xwidth[110X  -  the  width  in  pixels  of  the visualization to produce. If
        omitted,  the  tool  usually  fills  the width available. In a Jupyter
        Notebook  output  cell, this is the width of the cell. A visualization
        shown  outside  of a Jupyter notebook will take up the entire width of
        the web page in which it is displayed.[133X
  
  [30X    [33X[0;6Y[10Xtitle[110X  -  the title to place at the top of the chart, as a string. Can
        be omitted.[133X
  
  [30X    [33X[0;6Y[10Xxaxis[110X  -  the  text  to  write  below  the [23Xx[123X axis, as a string. Can be
        omitted.[133X
  
  [30X    [33X[0;6Y[10Xyaxis[110X  - the text to write to the left of the [23Xy[123X axis, as a string. Can
        be omitted.[133X
  
  [30X    [33X[0;6Y[10Xname[110X  - this option should be specified in the options object for each
        separate  data series, as opposed to just once for the entire plot. It
        assigns  a  string name to that data series, typically included in the
        chart's legend.[133X
  
  
  [1X2.3 [33X[0;0YGraphs[133X[101X
  
  [33X[0;0YThis  section  covers  the [2XPlotGraph[102X ([14X7.1-3[114X) function in the high-level API,
  which  is used for drawing graphs. If invoked in a Jupyter Notebook, it will
  show  the  resulting  visualization  in  the  appropriate output cell of the
  notebook.  If  invoked  from  the  [5XGAP[105X  command line, it will use the system
  default web browser to show the resulting visualization. This section covers
  that  function through a series of examples, but you can see full details in
  the function reference in Chapter [14X7[114X.[133X
  
  [33X[0;0YYou  can  make a graph by calling [2XPlotGraph[102X ([14X7.1-3[114X) on a list of edges, each
  of which is a pair (a list of length two).[133X
  
  [4X[32X  Example  [32X[104X
    [4X[28XPlotGraph( [ [ "start", "option1" ], [ "start", "option2" ],[128X[104X
    [4X[28X             [ "option1", "end" ], [ "option2", "end" ] ] );[128X[104X
  [4X[32X[104X
  
  [33X[0;0YResulting image not shown here.[133X
  
  [33X[0;0YVertex  names  can be strings, as shown above, or any [5XGAP[105X data; they will be
  converted  to strings using [10XPrintString[110X. As you can see, the set of vertices
  is  assumed  to  be  the  set  of things mentioned in the edges. But you can
  specify the vertex set separately.[133X
  
  [33X[0;0YFor  example,  if  you wanted to graph the divisibility relation on a set of
  integers, some elements may not be included in any edge.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[28XPlotGraph( [ 2 .. 10 ],[128X[104X
    [4X[28X           [ [ 2, 4 ], [ 2, 6 ], [ 2, 8 ], [ 2, 10 ],[128X[104X
    [4X[28X             [ 3, 6 ], [ 3, 9 ], [ 4, 8 ], [ 5, 10 ] ] );[128X[104X
  [4X[32X[104X
  
  [33X[0;0YResulting image not shown here.[133X
  
  [33X[0;0YBut for anything other than a small graph, specifying the vertex or edge set
  manually  may be inconvenient. Thus if you have a vertex set, you can create
  the  edge  set  by  passing  a binary relation as a [5XGAP[105X function. Here is an
  example to create a subgroup lattice.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[28XG := Group( (1,2,3), (1,2) );[128X[104X
    [4X[28XS := function ( H, G )[128X[104X
    [4X[28X    return IsSubgroup( G, H ) and H <> G;[128X[104X
    [4X[28Xend;[128X[104X
    [4X[28XPlotGraph( AllSubgroups( G ), S );[128X[104X
  [4X[32X[104X
  
  [33X[0;0YResulting image not shown here.[133X
  
  [33X[0;0YBut  all three of the graphs just shown would be better if they had directed
  edges.  And  we might want to organize them differently in the view, perhaps
  even  with  some colors, etc. To this end, you can pass an options parameter
  as  the  final  parameter  to  [2XPlotGraph[102X ([14X7.1-3[114X), just as you could for [2XPlot[102X
  ([14X7.1-1[114X).[133X
  
  [4X[32X  Example  [32X[104X
    [4X[28XG := Group( (1,2,3), (1,2) );[128X[104X
    [4X[28XS := function ( H, G )[128X[104X
    [4X[28X    return IsSubgroup( G, H ) and H <> G;[128X[104X
    [4X[28Xend;[128X[104X
    [4X[28XPlotGraph( AllSubgroups( G ), S,[128X[104X
    [4X[28X    rec( directed := true, layout := "grid", arrowscale := 3 ) );[128X[104X
  [4X[32X[104X
  
  [33X[0;0YResulting image not shown here.[133X
  
  [33X[0;0YThe next section covers all options in detail.[133X
  
  
  [1X2.4 [33X[0;0YOptions for graphs[133X[101X
  
  [33X[0;0YThe  options  record  passed as the final parameter to [2XPlotGraph[102X ([14X7.1-3[114X) can
  have the following entries.[133X
  
  [30X    [33X[0;6Y[10Xtool[110X  -  the  visualization tool to use to make the plot, as a string.
        The  default  is  "cytoscape".  The full list of tools is available in
        Section [14X1.2[114X.[133X
  
  [30X    [33X[0;6Y[10Xlayout[110X  -  the  name  of  the  layout  algorithm  to use, as a string.
        Permitted  values  vary by tool. Currently cytoscape supports "preset"
        (meaning  you  must  have  specified  the  nodes' positions manually),
        "cose"  (virtual-spring-based  automatic  layout),  "random",  "grid",
        "circle",    "concentric"    (multiple    concentric   circles),   and
        "breadthfirst" (a hierarchy).[133X
  
  [30X    [33X[0;6Y[10Xvertexwidth[110X and [10Xvertexheight[110X - the dimensions of each vertex.[133X
  
  [30X    [33X[0;6Y[10Xvertexcolor[110X - the color of the vertices in the graph. This should be a
        string representing an HTML color, such as "#ccc" or "red".[133X
  
  [30X    [33X[0;6Y[10Xedgewidth[110X - the thickness of each edge.[133X
  
  [30X    [33X[0;6Y[10Xedgecolor[110X  -  the color of each edge and its corresponding arrow. This
        should  be  a  string  representing  an  HTML color, such as "#ccc" or
        "red".[133X
  
  [30X    [33X[0;6Y[10Xdirected[110X  -  a  boolean defaulting to false, whether to draw arrows to
        visually indicate that the graph is a directed graph[133X
  
  [30X    [33X[0;6Y[10Xarrowscale[110X  -  a multiplier to increase or decrease the size of arrows
        in a directed graph.[133X
  
  [30X    [33X[0;6Y[10Xheight[110X  -  the  height  in  pixels  of the visualization to produce. A
        sensible default is provided, which varies by tool.[133X
  
  [30X    [33X[0;6Y[10Xwidth[110X  -  the  width  in  pixels  of  the visualization to produce. If
        omitted,  the  tool  usually  fills  the width available. In a Jupyter
        Notebook  output  cell, this is the width of the cell. A visualization
        shown  outside  of a Jupyter notebook will take up the entire width of
        the web page in which it is displayed.[133X
  
