d.linegraph.html 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <h2>DESCRIPTION</h2>
  2. <em>d.linegraph</em> is a module to draw simple x,y line graphs
  3. (plots) based on numerical data contained in separate files.
  4. <h3>Data format</h3>
  5. The X and Y data files for the graph are essentially a column of numbers in
  6. each file, with one input number per line. The program expects that each X
  7. value will have a corresponding Y value, therefore the number of lines in
  8. each data input file should be the same. Essentially, the X data becomes
  9. the X axis reference to which the Y data is plotted as a line. Therefore,
  10. the X data should be a monotonically increasing progression of numbers (i.e.
  11. "1,2,3,..."; "0, 10, 100, 1000,..."; "...-5,-1,0,1,5..."). If multiple Y
  12. data files are used, the Y axis scale will be based on the range of minimum
  13. and maximum values from all Y files, then all Y data given will be graphed
  14. according to that Y scale. Therefore, if multiple Y data inputs are used
  15. with dissimilar units, the graph produced comparing the two will be
  16. deceptive.
  17. <h3>File inputs</h3>
  18. If the <b>directory</b> option is provided, the paths to files can (and
  19. should) be only relative paths to these files. While this is not recommended
  20. for scripting, it can be advantageous when typing the paths
  21. manually. For example when all files are stored in the directory
  22. <tt>/home/john/data</tt>, the user can provide the following in the command
  23. line:
  24. <div class="code"><pre>
  25. d.linegraph directory=/home/john/data x_file=x.txt y_file=y1.txt,y2.txt
  26. </pre></div>
  27. <h3>Managing colors</h3>
  28. The user can specify the <b>y_color</b> option, the <b>color_table</b>
  29. option or just leave the defaults to influence the color of the
  30. plotted lines.
  31. <p>
  32. Colors specified by <b>y_color</b> option are used for drawing the lines
  33. in the graph. If multiple Y data files are used, an equal number of
  34. colors may be used to control the colors of the lines. Colors will be
  35. assigned to Y data in respect to the sequence of instantiation on the
  36. command line. It can be one of GRASS GIS named colors or the RGB
  37. values from 0-255 separated by colons (RRR:GGG:BBB).
  38. <p>
  39. Alternatively, the user can use the <b>color_table</b> option to specify one
  40. of the GRASS GIS predefined color tables.
  41. <p>
  42. By default, a series of colors will be chosen by the module if none are
  43. provided upon invocation. The order of default colors is red, green,
  44. violet, blue, orange, gray, brown, magenta, white, and indigo. The user is
  45. advised not to rely on the order of default colors but to either use the
  46. <b>y_color</b> or the <b>color_table</b> option to obtain predictable and
  47. reproducible results.
  48. <p>
  49. The color to be used for titles, axis lines, tics, and scale numbers
  50. is determined by the <b>title_color</b> option. The user can provide
  51. one of the GRASS GIS named colors (such as gray, white, or black)
  52. or use the GRASS GIS colon-separated format for RGB (RRR:GGG:BBB).
  53. <h3>Titles, labels, and tics</h3>
  54. The <b>title</b> option specifies the text for the title of the graph.
  55. It will be centered over the top of graph.
  56. The <b>x_title</b> option is a text to describe data for X axis. It will be
  57. centered beneath the graph. Default is no text unless there is a need
  58. for a unit descriptor determined by the <em>d.linegraph</em> module,
  59. then string such as "in hundreds" is generated.
  60. The <b>y_title</b> option is a text to describe data for Y axis. It
  61. will be centered beneath the X data description. Similarly, to the
  62. <b>x_title</b> option, default is no text unless there is a need for an
  63. auto-generated description. In the case of graphs with multiple lines
  64. (multiple inputs for Y axis), user may wish to use more specific text
  65. placement using the <em><a href="d.text.html">d.text</a></em> or
  66. <em><a href="v.label.html">v.label</a></em> programs.
  67. <h2>NOTES</h2>
  68. For historical reasons, the <em>d.linegraph</em> module accepts
  69. titles of more than one word where the underscore character ("_")
  70. is used to represent spaces (" "). For example "Census_data_1990" would be
  71. printed over the graph as "Census data 1990". The use of underscores is not
  72. necessary to use as long as the parameter is quoted in the command line.
  73. In general, use of underscores is not recommended and there is no need to use
  74. it at all in the GUI or when using <em>d.linegraph</em> in Python scripts.
  75. <p>
  76. The way the program locates and labels tic marks is less than perfect:
  77. <br>
  78. 1) although distances between Y tics are proportional to the value, they are
  79. not proportional on the X axis;
  80. <br>
  81. 2) decimal values between -1 and 1 can be printed on the X axis, but not
  82. on Y. (With respect to the later, the input for Y values can all be
  83. multiplied by a factor of 10 before graphing).
  84. <p>
  85. Depending on the user's needs, it might be easier or more appropriate
  86. to use a 3rd party tool such as xgraph, gnuplot, Matplotlib in Python,
  87. or R instead of <em>d.linegraph</em>.
  88. For a more general solution for plotting in GRASS GIS, the user is
  89. advised to use the <em><a href="d.graph.html">d.graph</a></em> module.
  90. <h2>EXAMPLE</h2>
  91. The following can be executed in Bash to create the input data for this
  92. example. The user can just create these files in a text editor, save
  93. them and specify path to them.
  94. <div class="code"><pre>
  95. cat &gt; x.txt &lt;&lt;EOF
  96. 1
  97. 3
  98. 4
  99. 6
  100. 9
  101. EOF
  102. cat &gt; y1.txt &lt;&lt;EOF
  103. 50
  104. 58
  105. 65
  106. 34
  107. 27
  108. EOF
  109. cat &gt; y2.txt &lt;&lt;EOF
  110. 10
  111. 20
  112. 35
  113. 50
  114. 45
  115. EOF
  116. </pre></div>
  117. <!--
  118. export GRASS_FONT=sans # fixes bad default font
  119. d.mon start=cairo output=plot.png width=400 height=400
  120. d.erase # previous image is not cleaned
  121. -->
  122. <p>
  123. The next command sequence creates a file <tt>plot.png</tt> in the current
  124. directory which is the drawing made by <em>d.linegraph</em>.
  125. <div class="code"><pre>
  126. d.mon start=cairo output=plot.png width=400 height=400
  127. d.linegraph x_file=x.txt y_file=y1.txt,y2.txt
  128. d.mon stop=cairo
  129. </pre></div>
  130. <h2>SEE ALSO</h2>
  131. <em>
  132. <a href="d.frame.html">d.frame</a>,
  133. <a href="d.text.html">d.text</a>,
  134. <a href="v.label.html">v.label</a>,
  135. <a href="d.graph.html">d.graph</a>,
  136. <a href="d.histogram.html">d.histogram</a>
  137. </em>
  138. <h2>AUTHOR</h2>
  139. Chris Rewerts, Agricultural Engineering, Purdue University
  140. <p><i>Last changed: $Date$</i>