Depic line graph
Author(s): Isabel Martín García.This module defines predicates which depict line graph and scatter graph widgets. All eigth predicates exported by this module plot two-variable data. Each point is defined by its X-Y coordinate values. A dataset is defined by two lists xvector and yvector, which contain the points coordinates. As you might guess, the values placed in the the same position in both lists are the coordinates of a point. They both share the following features:
- Numeric values for vector elements are needed. We'll use two vectors to represent the X-Y coordinates of each set of plotted data, but in this case every dataset shares the X-vector, i.e., x-coordinate of points with the same index
Note: It should be pointed out that I am refering to an index as the position of an element in a list.
in different datasets is the same. Thus, the numbers of points in each yvector must be equal to the number of points in the xvector.
- The active element color is navyblue, which means that when you select a legend element, the corresponding line or point dataset turns into navyblue.
- The user can either select the appearance of the lines and/or points of each dataset or not. If not, the system will choose the colors for the lines and the points among the available ones in accordance with the plot background color and it will also set the points size and symbol to the default. If the plot background color is black, the system will choose a lighter color, and the system will select a darker color when the plot background color is white. Thus, the user can define the appearanse attributes of each dataset in four different ways. Take a look at the attributes/1 type definition and see the examples to understand it clearly.
- The graph has a legend and one entry (symbol and label) per dataset.
- If you do not want to display text in the element header, barchart title, xaxis title, yaxis title or footer, simply give ” as the value of the argument.
- The predicates check whether the format of the arguments is correct as well. The testing process involves some verifications. If one or both vectors are empty, the exception error2 will be thrown. If the vectors contains elements but are not correct, the exception error4 will be thrown.
The names of the line graph predicates begin with graph_ and those corresponding to the scatter graph group begin with scattergraph_.
Usage and interface
- Library usage:
:- use_module(library(gengraph1)). - Exports:
- Predicates:
graph_b1/9, graph_b1/13, graph_w1/9, graph_w1/13, scattergraph_b1/8, scattergraph_b1/12, scattergraph_w1/8, scattergraph_w1/12. - Regular Types:
vector/1, smooth/1, attributes/1, symbol/1, size/1.
- Predicates:
- Imports:
- System library modules:
chartlib/bltclass, chartlib/genbar1, chartlib/color_pattern, chartlib/test_format, chartlib/install_utils, lists, random/random. - Packages:
prelude, nonpure, assertions, regtypes, isomodes.
- System library modules:
Documentation on exports
Besides the features mentioned at the begining of the chapter, the displayed graph generated when calling this predicate has the following distinguishing characteristics:
- The plotting area background color is black.
- The cross hairs color is white.
- The axes limits are determined from the data.
Example:
graph_b1('This is the header text', 'Graph_title', 'xaxistitle', [20,10,59], 'yaxixtitle', [ [10,35,40],[25,50,60] ], [ ['element1','Blue','Yellow','plus',6],['element2',Outline,Color] ], 'footer', 'linear').
Usage:
- The following properties should hold at call time:
(genbar1:header/1)Header is a text (an atom) describing the header of the graph.
(genbar1:title/1)GTitle is a text (an atom) to be used as label, usually not very long.
(genbar1:title/1)XTitle is a text (an atom) to be used as label, usually not very long.
(gengraph1:vector/1)gengraph1:vector(XVector)
(genbar1:title/1)YTitle is a text (an atom) to be used as label, usually not very long.
(basic_props:list/2)YVectors is a list of vectors.
(basic_props:list/2)LAtts is a list of attributess.
(genbar1:footer/1)Footer is a text (an atom) describing the footer of the graph.
(gengraph1:smooth/1)gengraph1:smooth(Smooth)
The particular features related to this predicate are described below:
- The plotting area background color is black.
- The cross hairs color is white.
- You can set the minimum and maximum limits of the axes. Data outside the limits will not be plotted.
Example:
graph_b1('This is the header text', 'Graph_title', 'xaxistitle', [20,10,59], 50, _, 'yaxixtitle', [[10,35,40],[25,50,60]], 50, _, [['line1','circle',4],['line2',OutlineColor,Color]], 'footer', 'step').
Usage:
- The following properties should hold at call time:
(genbar1:header/1)Header is a text (an atom) describing the header of the graph.
(genbar1:title/1)GT is a text (an atom) to be used as label, usually not very long.
(genbar1:title/1)XT is a text (an atom) to be used as label, usually not very long.
(gengraph1:vector/1)gengraph1:vector(XV)
(genbar1:axis_limit/1)genbar1:axis_limit(XMax)
(genbar1:axis_limit/1)genbar1:axis_limit(XMin)
(genbar1:title/1)YT is a text (an atom) to be used as label, usually not very long.
(basic_props:list/2)YVs is a list of vectors.
(genbar1:axis_limit/1)genbar1:axis_limit(YMax)
(genbar1:axis_limit/1)genbar1:axis_limit(YMin)
(basic_props:list/2)LAtts is a list of attributess.
(genbar1:footer/1)Footer is a text (an atom) describing the footer of the graph.
(gengraph1:smooth/1)gengraph1:smooth(Smooth)
This predicate is quite similar to graph_b1/9. The differences lies in the plot background color and in the cross hairs color, which are white and black respectively.
Example:
graph_w1('This is the header text', 'Graph_title', 'xaxistitle', [20,10,40,50], 'yaxixtitle', [ [10,35,40,50],[25,20,60,40] ], [['line1','Blue','DarkOrchid'],['line2','circle',3]], 'footer', 'quadratic').
Usage:
- The following properties should hold at call time:
(genbar1:header/1)Header is a text (an atom) describing the header of the graph.
(genbar1:title/1)GTitle is a text (an atom) to be used as label, usually not very long.
(genbar1:title/1)XTitle is a text (an atom) to be used as label, usually not very long.
(gengraph1:vector/1)gengraph1:vector(XVector)
(genbar1:title/1)YTitle is a text (an atom) to be used as label, usually not very long.
(basic_props:list/2)YVectors is a list of vectors.
(basic_props:list/2)LAtts is a list of attributess.
(genbar1:footer/1)Footer is a text (an atom) describing the footer of the graph.
(gengraph1:smooth/1)gengraph1:smooth(Smooth)
This predicate is quite similar to graph_b1/13, the differences between them are listed below:
- The plotting area background color is white.
- The cross hairs color is black.
Example:
graph_w1('This is the header text', 'Graph_title', 'xaxistitle', [20,10,59], 100, 10, 'yaxixtitle', [[10,35,40],[25,20,60]], _, _, [['element1','Blue','Yellow'],['element2','Turquoise','Plum']], 'footer', 'quadratic').
Usage:
- The following properties should hold at call time:
(genbar1:header/1)Header is a text (an atom) describing the header of the graph.
(genbar1:title/1)GT is a text (an atom) to be used as label, usually not very long.
(genbar1:title/1)XT is a text (an atom) to be used as label, usually not very long.
(gengraph1:vector/1)gengraph1:vector(XV)
(genbar1:axis_limit/1)genbar1:axis_limit(XMax)
(genbar1:axis_limit/1)genbar1:axis_limit(XMin)
(genbar1:title/1)YT is a text (an atom) to be used as label, usually not very long.
(basic_props:list/2)YVs is a list of vectors.
(genbar1:axis_limit/1)genbar1:axis_limit(YMax)
(genbar1:axis_limit/1)genbar1:axis_limit(YMin)
(basic_props:list/2)LAtts is a list of attributess.
(genbar1:footer/1)Footer is a text (an atom) describing the footer of the graph.
(gengraph1:smooth/1)gengraph1:smooth(Smooth)
Apart from the features brought up at the beginning of the chapter, the scatter graph displayed invoking this predicate has the following characteristics:
- The plotting area background color is black.
- The cross hairs color is white.
- The axes limits are determined from the data.
Example:
scattergraph_b1('This is the header text', 'Graph_title', 'xaxistitle', [10,15,20], 'yaxixtitle', [[10,35,20],[15,11,21]], [['element1','Blue','Yellow'],['element2','Turquoise','Plum']], 'footer').
Usage:
- The following properties should hold at call time:
(genbar1:header/1)Header is a text (an atom) describing the header of the graph.
(genbar1:title/1)GTitle is a text (an atom) to be used as label, usually not very long.
(genbar1:title/1)XTitle is a text (an atom) to be used as label, usually not very long.
(gengraph1:vector/1)gengraph1:vector(XVector)
(genbar1:title/1)YTitle is a text (an atom) to be used as label, usually not very long.
(basic_props:list/2)YVectors is a list of vectors.
(basic_props:list/2)PAtts is a list of attributess.
(genbar1:footer/1)Footer is a text (an atom) describing the footer of the graph.
The particular features related to this predicate are described below:
- The plotting area background color is black.
- The cross hairs color is white.
- You can set the minimum and maximum limits of the axes. Data outside the limits will not be plotted.
Example:
scattergraph_b1('This is the header text', 'Graph_title', 'xaxistitle', [20,10,59], 50, _, 'yaxixtitle', [[10,35,40],[25,50,60]], 50, _, [['point dataset1','Blue','Yellow'],['point dataset2']], 'footer').
Usage:
- The following properties should hold at call time:
(genbar1:header/1)Header is a text (an atom) describing the header of the graph.
(genbar1:title/1)GT is a text (an atom) to be used as label, usually not very long.
(genbar1:title/1)XT is a text (an atom) to be used as label, usually not very long.
(gengraph1:vector/1)gengraph1:vector(XV)
(genbar1:axis_limit/1)genbar1:axis_limit(XMax)
(genbar1:axis_limit/1)genbar1:axis_limit(XMin)
(genbar1:title/1)YT is a text (an atom) to be used as label, usually not very long.
(basic_props:list/2)YVs is a list of vectors.
(genbar1:axis_limit/1)genbar1:axis_limit(YMax)
(genbar1:axis_limit/1)genbar1:axis_limit(YMin)
(basic_props:list/2)PAtts is a list of attributess.
(genbar1:footer/1)Footer is a text (an atom) describing the footer of the graph.
This predicate is quite similar to scattergraph_b1/8 except in the following:
- The plotting area background color is black.
- The cross hairs color is white.
- If the user does not fix the points colors, they will be chosen among the lighter ones.
Example:
scattergraph_w1('This is the header text', 'Graph_title', 'xaxistitle', [20,10,59], 'yaxixtitle', [[10,35,40],[25,20,60]], [['e1','Blue','Green'],['e2','MediumVioletRed','Plum']], 'footer').
Usage:
- The following properties should hold at call time:
(genbar1:header/1)Header is a text (an atom) describing the header of the graph.
(genbar1:title/1)GT is a text (an atom) to be used as label, usually not very long.
(genbar1:title/1)XT is a text (an atom) to be used as label, usually not very long.
(gengraph1:vector/1)gengraph1:vector(XVector)
(genbar1:title/1)YT is a text (an atom) to be used as label, usually not very long.
(basic_props:list/2)YVectors is a list of vectors.
(basic_props:list/2)PAtts is a list of attributess.
(genbar1:footer/1)Footer is a text (an atom) describing the footer of the graph.
This predicate is quite similar to scattergraph1_b1/13, the differences between them are listed below:
- The plotting area background color is white.
- The cross hairs color is black.
Example:
scattergraph_w1('This is the header text', 'Graph_title', 'xaxistitle', [20,10,59], 150, 5, 'yaxixtitle', [[10,35,40],[25,20,60]], _, -10, [['e1','Blue','Yellow'],['e2','MediumTurquoise','Plum']], 'footer').
Usage:
- The following properties should hold at call time:
(genbar1:header/1)Header is a text (an atom) describing the header of the graph.
(genbar1:title/1)GT is a text (an atom) to be used as label, usually not very long.
(genbar1:title/1)XT is a text (an atom) to be used as label, usually not very long.
(gengraph1:vector/1)gengraph1:vector(XV)
(genbar1:axis_limit/1)genbar1:axis_limit(XMax)
(genbar1:axis_limit/1)genbar1:axis_limit(XMin)
(genbar1:title/1)YT is a text (an atom) to be used as label, usually not very long.
(basic_props:list/2)YVs is a list of vectors.
(genbar1:axis_limit/1)genbar1:axis_limit(YMax)
(genbar1:axis_limit/1)genbar1:axis_limit(YMin)
(basic_props:list/2)PAtts is a list of attributess.
(genbar1:footer/1)Footer is a text (an atom) describing the footer of the graph.
vector(X) :- list(X,number).The type vector defines a list of numbers (integers or floats).
smooth(linear). smooth(cubic). smooth(quadratic). smooth(step).
Specifies how connecting segments are drawn between data points. If Smooth is linear, a single line segment is drawn, connecting both data points. When Smooth is step, two line segments will be drawn, the first line is a horizontal line segment that steps the next X-coordinate and the second one is a vertical line, moving to the next Y-coordinate. Both cubic and quadratic generate multiple segments between data points. If cubicis used, the segments are generated using a cubic spline. If quadratic, a quadratic spline is used. The default is linear.
attributes([ElementName]) :- atomic(ElementName). attributes([ElementName,OutLine,Color]) :- atomic(ElementName), color(OutLine), color(Color). attributes([ElementName,Symbol,Size]) :- atomic(ElementName), symbol(Symbol), size(Size). attributes([ElementName,OutLine,Color,Symbol,Size]) :- atomic(ElementName), color(OutLine), color(Color), symbol(Symbol), size(Size).
Each line or point dataset in the graph has its own attributes, which are defined by this type. The name of the dataset, specified in the ElementName argument, may be either a number or an atom. The second argument is the color of a thin line around each point in the dataset and the Color argument is the points and lines color. Both OutLine and Color must be a valid color (see available values in color/1), otherwise a random color according to the plot background color will be selected. The Symbol must be a valid symbol and the Size must be a number. Be careful if you want to especify the Symbol and the Size, otherwise the predicate will not work as you expect. If you don't select a symbol and a size for a dataset the default values will be square and 1 pixel.
symbol(square). symbol(circle). symbol(diamond). symbol(plus). symbol(cross). symbol(splus). symbol(scross). symbol(triangle).Symbol stands for the shape of the points whether in scatter graphs or in line graphs.
size(Size) :- number(Size).Size stands for the size in pixels of the points whether in scatter graphs or in line graphs.