Boost logo

Boost-Commit :

From: pbristow_at_[hidden]
Date: 2008-05-24 12:32:31


Author: pbristow
Date: 2008-05-24 12:32:30 EDT (Sat, 24 May 2008)
New Revision: 45723
URL: http://svn.boost.org/trac/boost/changeset/45723

Log:
New autoscale examples.
Added:
   sandbox/SOC/2007/visualization/libs/svg_plot/example/auto_1d_containers.cpp (contents, props changed)
   sandbox/SOC/2007/visualization/libs/svg_plot/example/auto_1d_plot.cpp (contents, props changed)
   sandbox/SOC/2007/visualization/libs/svg_plot/example/auto_2d_plot.cpp (contents, props changed)

Added: sandbox/SOC/2007/visualization/libs/svg_plot/example/auto_1d_containers.cpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2007/visualization/libs/svg_plot/example/auto_1d_containers.cpp 2008-05-24 12:32:30 EDT (Sat, 24 May 2008)
@@ -0,0 +1,170 @@
+// auto_1d_containers.cpp
+
+// Copyright Paul A Bristow 2008
+
+// Use, modification and distribution are subject to the
+// Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt
+// or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+// An example to demonstrate autoscaling with *multiple* STL containers.
+// See also auto_1d_plot.cpp and auto_1d_container.cpp.
+
+// Caution: this file contains Quickbook markup as well as code
+// and comments: don't change any of the special comment markups!
+
+//[auto_1d_containers_1
+
+/*`First we need a few includes to use Boost.Plot
+(and some others only needed for this example).
+*/
+
+#include <boost/svg_plot/svg_1d_plot.hpp>
+ using namespace boost::svg;
+ using boost::svg::svg_1d_plot;
+
+#include <boost/svg_plot/detail/auto_axes.hpp>
+ using boost::svg::show; // A single STL container.
+ using boost::svg::show_all; // Multiple STL containers.
+ using boost::svg::range; // Find min and max of a STL container.
+ using boost::svg::range_all;// Find min and max of multipler STL containers.
+ // Note neither of these chack for 'limits' (infinite, NaN) values
+
+#include <boost/svg_plot/detail/pair.hpp>
+ using boost::svg::detail::operator<<; // Output pair as 1.23, 4.56
+
+//#include <boost/svg_plot/show_1d_settings.hpp>
+// Only needed for showing which settings in use.
+//void boost::svg::show_1d_plot_settings(svg_1d_plot&);
+
+#include <boost/algorithm/minmax.hpp>
+ using boost::minmax;
+#include <boost/algorithm/minmax_element.hpp>
+ using boost::minmax_element;
+
+#include <iostream>
+ using std::cout;
+ using std::endl;
+ using std::boolalpha;
+
+#include <limits>
+ using std::numeric_limits;
+
+#include <vector>
+ using std::vector;
+
+#include <utility>
+ using std::pair;
+ using boost::svg::detail::operator<<; // Output pair as 1.23, 4.56
+
+#include <algorithm>
+ using std::multiplies;
+ using std::transform;
+ using std::copy;
+#include <iterator>
+ using std::iterator;
+ using std::iterator_traits;
+ using std::ostream_iterator;
+
+//] [/auto_1d_containers_1]
+
+int main()
+{
+//[auto_1d_containers_2
+ /*`This example uses two containers to demonstrate autoscaling.
+ It is common to plot more than one set of data series together.
+ Autoscaling must probably inspect all the containers of these series
+ in order to find axis ranges that will be suitable for all of them.
+ */
+ vector<double> my_data_1;
+ // Initialize STL container my_data_1 with some entirely fictional data.
+ my_data_1.push_back(0.2); // [0]
+ my_data_1.push_back(1.1); // [1]
+ my_data_1.push_back(4.2); // [2]
+ my_data_1.push_back(3.3); // [3]
+ my_data_1.push_back(5.4); // [4]
+ my_data_1.push_back(6.5); // [5]
+
+ /*`
+ We might use some convenient functions to list the container to cout.
+ */
+ show(my_data_1); // Entire container contents.
+ /*`
+ Others are easily written, often using std::copy, for example:
+ ``
+ copy(my_data_1_2.begin(), my_data_1_2.end(), ostream_iterator<double>(cout, " "));
+ ``
+ */
+ /*`
+ Now we concoct another equally fictional data series by a transform multiplying by 2.3.
+ */
+
+ vector<double> my_data_2; // Create a second data series.
+ copy(my_data_1.begin(), my_data_1.end(), back_inserter(my_data_2));
+ // Change the values in an entirely arbitrary way (each * 2.3).
+ transform(my_data_2.begin(), my_data_2.end(), my_data_2.begin(), bind1st(multiplies<double>(), 2.3));
+ //cout << endl << my_data.size() << " values in my_data_2. " << endl;
+
+ /*`Next we need a new STL container, vector say, to hold our multiple containers of data series.
+ They must all be the same STL container type, in this example, vector<double>.
+ And we use pushback to add the containers.
+ */
+ vector<vector<double> > my_containers;
+
+ my_containers.push_back(my_data_1); // Add 1st data series.
+ my_containers.push_back(my_data_2); // Add another data series.
+ cout << my_containers.size() << " containers." << endl;
+ show_all(my_containers);
+
+ /*` Finally we can use all the containers to find the minimum of mimimums and maximum of maximums
+ ready to feed into the plot autoscale function.
+ */
+ pair<double, double> mm = range_all(my_containers);
+ cout << "Data range: " << mm << endl; // min & max of all data.
+ svg_1d_plot my_1d_plot; // Construct a plot with all the default constructor values.
+
+ /*`We could feed the minimum and maximum values separately,*/
+ my_1d_plot.x_autoscale(mm.first, mm.second); // Use minimum and maximum to autoscale.
+ /*`
+ but usually feeding the pair is more convenient.
+ (Perhaps we might want to impose some other minimum and maximum here).
+ */
+ my_1d_plot.x_autoscale(mm); // Use overall minimum and maximum to autoscale.
+
+ /*`Finally, we add the data series containers to the plot, and write the SVG out to file.*/
+ my_1d_plot.plot(my_data_1, "data_1");
+ my_1d_plot.plot(my_data_2, "data_2");
+
+ my_1d_plot.write("auto_1d_containers.svg"); // Write the plot to file.
+
+ /*`If we want, we can check the autoscale range used, or even all the plot settings.*/
+ cout << "x_range() " << my_1d_plot.x_range() << endl; // x_range() 0, 15
+ //show_1d_plot_settings(my_1d_plot); // If required.
+
+//] [/auto_1d_containers_2]
+
+ return 0;
+} // int main()
+
+/*
+
+//[auto_1d_containers_output
+
+Compiling...
+auto_1d_containers.cpp
+Linking...
+Embedding manifest...
+Autorun "j:\Cpp\SVG\debug\auto_1d_containers.exe"
+6 values in container: 0.2 1.1 4.2 3.3 5.4 6.5
+2 containers.
+6 values in container: 0.2 1.1 4.2 3.3 5.4 6.5
+6 values in container: 0.46 2.53 9.66 7.59 12.42 14.95
+Data range: 0.2, 14.9
+x_range() 0, 15
+Build Time 0:03
+
+//] [/auto_1d_containers_output]
+
+
+*/
+

Added: sandbox/SOC/2007/visualization/libs/svg_plot/example/auto_1d_plot.cpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2007/visualization/libs/svg_plot/example/auto_1d_plot.cpp 2008-05-24 12:32:30 EDT (Sat, 24 May 2008)
@@ -0,0 +1,375 @@
+// auto_1d_plot.cpp
+
+// Copyright Jacob Voytko 2007
+// Copyright Paul A Bristow 2008
+
+// Use, modification and distribution are subject to the
+// Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt
+// or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+// An example to demonstrate simple 1D settings, including *auto-scaling*.
+// See auto_1d_containers.cpp for an example autoscaling with multiple data series.
+// See also demo_1d_plot.cpp for a wider range of use.
+
+// This file is written to be included from a Quickbook .qbk document.
+// It can be compiled by the C++ compiler, and run. Any output can
+// also be added here as comment or included or pasted in elsewhere.
+
+// Caution: this file contains Quickbook markup as well as code
+// and comments: don't change any of the special comment markups!
+
+
+//[auto_1d_plot_1
+
+/*`First we need a few includes to use Boost.Plot
+(and some others only needed for this example).
+*/
+
+#include <boost/svg_plot/svg_1d_plot.hpp>
+ using namespace boost::svg;
+ using boost::svg::svg_1d_plot;
+
+#include <boost/svg_plot/show_1d_settings.hpp>
+// Only needed for showing which settings in use.
+ void boost::svg::show_1d_plot_settings(svg_1d_plot&);
+ // (Also provides operator<< for std::pair).
+
+#include <boost/algorithm/minmax.hpp>
+ using boost::minmax;
+#include <boost/algorithm/minmax_element.hpp>
+ using boost::minmax_element;
+
+#include <iostream> // for debugging.
+ using std::cout;
+ using std::endl;
+ using std::boolalpha;
+
+#include <limits>
+ using std::numeric_limits;
+
+#include <vector>
+ using std::vector;
+#include <set>
+ using std::multiset;
+
+#include <utility>
+ using std::pair;
+
+#include <boost/svg_plot/detail/auto_axes.hpp>
+ using boost::svg::show; // A single STL container.
+ using boost::svg::show_all; // Multiple STL containers.
+ using boost::svg::range; // Find min and max of a STL container.
+ using boost::svg::range_all;// Find min and max of multipler STL containers.
+
+//] [/auto_1d_plot_1]
+
+void scale_axis(double min_value, double max_value, // input
+ double* axis_min_value, double* axis_max_value, double* axis_tick_increment, // updated.
+ bool origin, double tight, int min_ticks, int steps);
+
+double tol100eps = 1000 * numeric_limits<double>::epsilon(); // suitable tight value.
+
+int main()
+{
+ //[auto_1d_plot_2
+ /*`This example uses containers to demonstrate autoscaling.
+ Autoscaling must inspect the container in order to find axis ranges that will be suitable.
+ First we create a container and fill with some fictional data.
+ */
+ vector<double> my_data;
+ // Initialize my_data with some entirely fictional data.
+ my_data.push_back(0.2);
+ my_data.push_back(1.1); // [1]
+ my_data.push_back(4.2); // [2]
+ my_data.push_back(3.3); // [3]
+ my_data.push_back(5.4); // [4]
+ my_data.push_back(6.5); // [5]
+
+ /*`Also included is an 'at limit' value that could confuse autoscaling.
+ Obviously we do not want the plot range to include infinity.*/
+ my_data.push_back(numeric_limits<double>::infinity()); // [6]
+
+ try
+ { // Ensure error, warning and information messages are displayed by the catch block.
+ double mn;
+ double mx;
+ int good = mnmx(my_data.begin(), my_data.end(), &mn, &mx);
+ cout << good << " good values, " << my_data.size() - good << " limit values." << endl;
+
+ using boost::svg::detail::operator<<; // For displaying std::pair.
+ svg_1d_plot my_1d_plot; // Construct a plot with all the default constructor values.
+ my_1d_plot.x_autoscale(my_data); // Compute autoscale values for the plot.
+ my_1d_plot.plot(my_data, "Default 1D"); // Add the one data series, and give it a title.
+ my_1d_plot.write("auto_1d_plot.svg"); // Write the plot to file.
+
+ /*`It may be useful to display that range chosen by autoscaling. */
+ cout << "x_range() " << my_1d_plot.x_range() << endl; // x_range()
+ }
+ catch(const std::exception& e)
+ { // Error, warning and information messages are displayed by the catch block.
+ std::cout <<
+ "\n""Message from thrown exception was:\n " << e.what() << std::endl;
+ }
+ //] [/auto_1d_plot_2]
+
+ //[auto_1d_plot_3
+/*`Other STL containers can also be used, for example set, or multiset (allowing duplicates):*/
+
+ try
+ { // Ensure error, warning and information messages are displayed by the catch block.
+
+ multiset<double> my_set;
+ // Initialize my_set with some entirely fictional data.
+ my_set.insert(1.2);
+ my_set.insert(2.3);
+ my_set.insert(3.4);
+ my_set.insert(4.5);
+ my_set.insert(5.6);
+ my_set.insert(6.7);
+ my_set.insert(7.8);
+ my_set.insert(8.9);
+ // Some examples of showing the set using various iterators:
+ multiset<double>::const_iterator si;
+
+ show(my_data); // Entire container contents,
+ show(my_set); // for two different types of container.
+
+ // show(&my_data[0], &my_data[my_data.size()]); // pointers - wrong! uses more all data ;-)
+ show(&my_data[0], &my_data[my_data.size()-1]); // pointers, all data.
+ show(&my_data[1], &my_data[5]); // pointers, part data.
+ show(my_data.begin(), my_data.end()); // iterators.
+ show(++(my_data.begin()), --(my_data.end())); // Just the 4 middle values.
+
+ vector<double>::const_iterator idb = my_data.begin();
+ vector<double>::const_iterator ide = my_data.end();
+ show(idb, ide); // All
+ ++idb; // Move to 2nd value.
+ --ide; // move back from last value.
+ show(idb, ide); // Just the 4 middle values.
+
+ typedef vector<double>::const_iterator vector_iterator;
+ pair<vector_iterator, vector_iterator> result = boost::minmax_element(my_data.begin(), my_data.end());
+ cout << "The smallest element is " << *(result.first) << endl; // 0.2
+ cout << "The largest element is " << *(result.second) << endl; // 6.5
+
+/*`Autoscaling can also use two double min and max values provided by the user program.
+Using `x_autoscale(my_set)` effectively uses the first and last items in the STL container.
+If the container is sorted, then these are the minimum and maximum values.*/
+
+ double min_value = *(my_data.begin());
+ double max_value = *(--my_data.end());
+ cout << "my_set min " << min_value << ", max = " << max_value << endl;
+
+/*`Function scale_axis is used by autoscale, but is also available for use direct by the user.
+It accepts parameters controlling the scaling and updates 4 items. Its signature is:
+
+ ``void scale_axis(double min_value, double max_value, // Input range
+ double* axis_min_value, double* axis_max_value, double* axis_tick_increment, int* auto_ticks, // All 4 updated.
+ bool check_limits, // Whether to check all values for infinity, NaN etc.
+ bool origin, // If true, ensures that zero is a tick value.
+ double tight, // Allows user to avoid a small fraction over a tick using another tick.
+ int min_ticks, // Minimum number of ticks.
+ int steps); // Round up and down to 2, 4, 6, 8, 10, or 5, 10 or 2, 5, 10 systems.
+ ``
+
+ */
+ double axis_min_value; // Values to be updated by autoscale.
+ double axis_max_value;
+ double axis_tick_increment;
+ int axis_ticks;
+
+ /*`min_value` and `max_value` could be provided by the user program:
+ usually these values are derived in some way from the user data.
+ Several examples follow.*/
+
+ // Scaling using first and last values in container,
+ // assuming the data are ordered in ascending value,
+ // for example, set, map, multimap, or a sorted vector or array.
+ //scale_axis(*my_data.begin(),*(--my_data.end()),
+ scale_axis(1., 9.,
+ &axis_min_value, &axis_max_value, &axis_tick_increment, &axis_ticks,
+ false, tol100eps, 6, 0); // Display range.
+ cout << "scaled min " << axis_min_value << ", max = " << axis_max_value
+ << ", increment " << axis_tick_increment << ", axis ticks " << axis_ticks << endl;
+
+ // Scaling using two begin & end iterators into STL container,
+ // scale_axis does finding min and max.
+ scale_axis(my_data.begin(), my_data.end(),
+ &axis_min_value, &axis_max_value, &axis_tick_increment, &axis_ticks,
+ true, false, tol100eps, 6); // Display range.
+ cout << "scaled min " << axis_min_value << ", max = " << axis_max_value
+ << ", increment " << axis_tick_increment << ", axis ticks " << axis_ticks << endl;
+
+ // Scaling using two begin & end iterators into STL container,
+ // scale_axis does finding min and max.
+ scale_axis(my_data[1], my_data[4], // Only middle part of the container used, ignoring 1st and last values.
+ &axis_min_value, &axis_max_value, &axis_tick_increment, &axis_ticks,
+ false, tol100eps, 6); // Display range.
+ cout << "scaled min " << axis_min_value << ", max = " << axis_max_value
+ << ", increment " << axis_tick_increment << ", axis ticks " << axis_ticks << endl;
+
+ // Scaling using whole STL vector container,
+ // scale_axis does finding min and max.
+ scale_axis(my_data, &axis_min_value, &axis_max_value, &axis_tick_increment, &axis_ticks,
+ true, false, tol100eps, 6); // Display range.
+ cout << "scaled min " << axis_min_value << ", max = " << axis_max_value
+ << ", increment " << axis_tick_increment << ", axis ticks " << axis_ticks << endl;
+
+ // Scaling using whole STL set container,
+ // scale_axis does finding min and max.
+ scale_axis(my_set, &axis_min_value, &axis_max_value, &axis_tick_increment, &axis_ticks,
+ true, false, tol100eps, 6); // Display range.
+ cout << "scaled min " << axis_min_value << ", max = " << axis_max_value
+ << ", increment " << axis_tick_increment << ", axis ticks " << axis_ticks << endl;
+
+ /*`However there may be trouble if the data could contain values that are outside normal limits.
+ Infinity (+ and -), and maximum value, and NotaNumbers, are separated by the plot program to allow them to be shown,
+ but separate from 'normal' values. These values similarly can distort automatic scaling:
+ a single infinity would result in useless scaling!
+ When the plot range is set, the maximum and minimum values are checked,
+ and if not normal then an exception will be thrown, and no plot will be produced.
+ However, when autoscaling, it is more useful to ignore 'limit' values.
+ But this means checking all values individually. If it known that all values are normal,
+ for example because they come from some measuring equipment that is known only to produce normal values,
+ it will be much quicker to use std::min_max_element which can take advantange of knowledge of the container.
+
+ The function `autoscale_check_limits(bool)` is provided to control this.
+ If set true, all values will be checked, and those at 'limits' will be ignored in autoscaling.
+ The default is true, to check all values.
+
+ If we had many very known normal values to plot and want to autoscale,
+ we might instead opt to ignore these checks, and write:
+ */
+ svg_1d_plot my_1d_plot; // Construct a plot with all the default constructor values.
+
+ //my_1d_plot.autoscale_check_limits(false);
+ // This *will throw an exception* if checks are avoided and any values are at 'limits'.
+
+ // One could also intercept and change any values calculated by scale_axis here.
+ // Set the plot to use range and interval from the scale_axis values.
+ my_1d_plot.x_range(axis_min_value, axis_max_value)
+ .x_major_interval(axis_tick_increment);
+
+ my_1d_plot.x_autoscale(false); // Ensure autoscale values are *not* recalculated for the plot.
+
+/*`There are also some parameters which can fine-tune the autoscaling to produce more
+aesthetically pleasing ranges. One can:
+* enforce the inclusion of zero on the plot.
+* Specify a minimum number of major ticks.
+* Specify the steps between major ticks, default 0, or 2 for 2, 4, 6, 8, 10, 5 for 1, 5, 10, or 10 (2, 5, 10).
+* Avoid values that are a tiny amount over the minimum or maximum from causing an apparently empty tick at the minimum or maximum.
+*/
+
+ // Set some autoscaling parameters:
+ my_1d_plot.x_with_zero(false);
+ my_1d_plot.x_min_ticks(10);
+ my_1d_plot.x_steps(0);
+ my_1d_plot.x_tight(0.001);
+
+ // Show the flags just set.
+ cout << (my_1d_plot.x_with_zero() ? "x_with_zero, " : "not x_with_zero, ")
+ << my_1d_plot.x_min_ticks() << " x_min_ticks, "
+ << my_1d_plot.x_steps() << " x_steps, "
+ << my_1d_plot.x_tight() << " tightness." << endl;
+
+/*`Finally here are some examples of using autoscaling using all or part of containers.
+*/
+
+ my_1d_plot.x_autoscale(my_data); // Use all my_data to autoscale.
+ cout << "Autoscaled " // Show the results of autoscale:
+ "min " << my_1d_plot.x_auto_min_value()
+ << ", max "<< my_1d_plot.x_auto_max_value()
+ << ", interval " << my_1d_plot.x_auto_tick_interval() << endl; // Autoscaled min 0, max 6.5, interval 0.5
+
+ my_1d_plot.x_autoscale(my_data.begin(), my_data.end()); // Use all my_data to autoscale.
+
+ cout << "Autoscaled " // Show the results of autoscale:
+ "min " << my_1d_plot.x_auto_min_value()
+ << ", max "<< my_1d_plot.x_auto_max_value()
+ << ", interval " << my_1d_plot.x_auto_tick_interval() << endl; // Autoscaled min 0, max 6.5, interval 0.5
+
+ my_1d_plot.x_autoscale(my_data[1], my_data[4]); // Use only part of my_data to autoscale.
+
+ cout << "Autoscaled " // Show the results of autoscale:
+ "min " << my_1d_plot.x_auto_min_value()
+ << ", max "<< my_1d_plot.x_auto_max_value()
+ << ", interval " << my_1d_plot.x_auto_tick_interval() << endl; // Autoscaled min 1, max 5.5, interval 0.5
+
+ //my_1d_plot.x_autoscale(true); // Ensure autoscale values are used for the plot.
+ // This is also automatically set true by any call of `x_autoscale(some_data);`
+
+
+/*`The actual addition of data values to the plot is, of course, quite separate from any autoscaling.
+*/
+ my_1d_plot.plot(my_data, "Auto 1D"); // Add the one data series.
+ cout << "Autoscaled " // Show the results of autoscale:
+ " min " << my_1d_plot.x_auto_min_value()
+ << ", max "<< my_1d_plot.x_auto_max_value()
+ << ", interval " << my_1d_plot.x_auto_tick_interval() << endl; // Autoscaled min 1, max 5.5, interval 0.5
+
+ my_1d_plot.plot(my_set.begin(), my_set.end(), "Auto 1D"); // Add another data series from my_set.
+ my_1d_plot.plot(my_set, "Auto 1D"); // Add another whole data series from my_set.
+ my_1d_plot.plot(&my_data[1], &my_data[4], "Auto 1D"); // Add part (1,2 3 but *not* 4) of the one data series.
+ //my_1d_plot.plot(&my_set[1], &my_set[4], "Auto 1D"); // operator[] is not defined for set container!
+
+ my_1d_plot.write("auto_1d_plot.svg"); // Write the plot to file.
+
+ using boost::svg::detail::operator<<;
+ cout << "x_range() " << my_1d_plot.x_range() << endl; // x_range() 1, 5.5
+ show_1d_plot_settings(my_1d_plot);
+ }
+ catch(const std::exception& e)
+ { // Error, warning and information messages are displayed by the catch block.
+ std::cout <<
+ "\n""Message from thrown exception was:\n " << e.what() << std::endl;
+ }
+
+/*`If necessary, one can obtain a complete listing of all the settings used.
+This is often useful when the plot does not meet expectations.
+*/
+
+//] [auto_1d_plot_3]
+
+ return 0;
+} // int main()
+
+/*
+
+auto_1d_plot.cpp
+Linking...
+Embedding manifest...
+Autorun "j:\Cpp\SVG\debug\auto_1d_plot.exe"
+limit value: 1.#INF
+6 good values, 1 limit values.
+7 values in container: 0.2 1.1 4.2 3.3 5.4 6.5 1.#INF
+8 values in container: 1.2 2.3 3.4 4.5 5.6 6.7 7.8 8.9
+0.2 1.1 4.2 3.3 5.4 6.5 : 6 values used.
+1.1 4.2 3.3 5.4 : 4 values used.
+0.2 1.1 4.2 3.3 5.4 6.5 1.#INF : 7 values used.
+1.1 4.2 3.3 5.4 6.5 : 5 values used.
+0.2 1.1 4.2 3.3 5.4 6.5 1.#INF : 7 values used.
+1.1 4.2 3.3 5.4 6.5 : 5 values used.
+The smallest element is 0.2
+The largest element is 1.#INF
+my_set min 0.2, max = 1.#INF
+scaled min 1, max = 9, increment 1, axis ticks 9
+limit value: 1.#INF
+scaled min 0, max = 7, increment 1, axis ticks 8
+scaled min 1, max = 6, increment 1, axis ticks 6
+limit value: 1.#INF
+scaled min 0, max = 7, increment 1, axis ticks 8
+scaled min 1, max = 9, increment 1, axis ticks 9
+not x_with_zero, 10 x_min_ticks, 0 x_steps, 0.001 tightness.
+limit value: 1.#INF
+Autoscaled min 0, max 6.5, interval 0.5
+limit value: 1.#INF
+Autoscaled min 0, max 6.5, interval 0.5
+Autoscaled min 1, max 5.5, interval 0.5
+Autoscaled min 1, max 5.5, interval 0.5
+x_range() 1, 5.5
+Build Time 0:03
+
+
+*/
+

Added: sandbox/SOC/2007/visualization/libs/svg_plot/example/auto_2d_plot.cpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2007/visualization/libs/svg_plot/example/auto_2d_plot.cpp 2008-05-24 12:32:30 EDT (Sat, 24 May 2008)
@@ -0,0 +1,168 @@
+// auto_2d_plot.cpp
+
+// Copyright Paul A Bristow 2008
+
+// Use, modification and distribution are subject to the
+// Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt
+// or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+// An example to demonstrate autoscaling with *multiple* STL containers.
+// See also auto_1d_plot.cpp and auto_1d_container.cpp.
+
+// Caution: this file contains Quickbook markup as well as code
+// and comments: don't change any of the special comment markups!
+
+//[auto_2d_plot_1
+
+/*`First we need a few includes to use Boost.Plot
+*/
+
+#include <boost/svg_plot/svg_2d_plot.hpp>
+ using namespace boost::svg;
+#include <utility>
+ using std::pair;
+#include <map>
+ using std::map;
+#include <set>
+ using std::multiset;
+#include <iostream>
+ using std::cout;
+ using std::endl;
+
+#include <limits>
+ using std::numeric_limits;
+
+#include <boost\math\special_functions\fpclassify.hpp>
+ using boost::math::isfinite;
+
+ // demo of getting the max and min of x and y
+template <class T> // T an STL container: array, vector ...
+void s(const T& container, // Container Data series to plot - entire container.
+ // (not necessarily ordered, so will find min and max).
+ double* x_min, double* x_max,
+ double* y_min, double* y_max
+ )
+{
+ typedef T::const_iterator iter;
+ std::pair<iter, iter> result = boost::minmax_element(container.begin(), container.end());
+ // minmax_element is efficient for maps because can use knowledge of being sorted,
+ // BUT only if it can be assumed that no values are 'at limits',
+ // infinity, NaN, max_value, min_value, denorm_min.
+ // Otherwise it is necessary to inspect all values individually.
+ pair<const double, double> px = *result.first;
+ pair<const double, double> py = *result.second;
+ *x_min = px.first;
+ *x_max = py.first;
+ *y_min = px.second;
+ *y_max = py.second;
+
+ cout << "s x_min " << *x_min << ", x_max " << *x_max << endl; // x_min 1, x_max 7.3
+ cout << "s y_min " << *y_min << ", y_max " << *y_max << endl; // y_min 3.2, y_max 9.1
+} // template <class T> int scale_axis T an STL container: array, vector ...
+
+
+//] [/auto_2d_plot_1]
+
+int main()
+{
+//[auto_2d_plot_2
+ /*`This example uses a single map to demonstrate autoscaling.
+ We create a map to hold our data series.
+ */
+ map<const double, double> my_map;
+ /*`
+ Inserting some fictional values also sorts the data.
+ The index value in [] is the x value.
+ */
+ my_map[1.1] = 3.2;
+ my_map[7.3] = 9.1;
+ my_map[2.1] = 5.4;
+
+/*`Also include some 'limits' values that would confuse autoscaling.
+*/
+ my_map[99.99] = numeric_limits<double>::quiet_NaN();
+ my_map[999.9] = numeric_limits<double>::infinity();
+ my_map[999.] = +numeric_limits<double>::infinity();
+
+
+
+ /*`Next a 2D plot is created using defaults for the very many possible settings.
+ */
+ svg_2d_plot my_plot;
+
+ /*`Add at least a title,
+ specify the both x and y axes are to use autoscaling,
+ and add the one data series to plotted.
+ */
+ my_plot.title("Autoscale example");
+ //my_plot.autoscale_check_limits(false); // Skip checks for speed.
+ // Will fail at run-time if any infinite or NaNs.
+
+ my_plot.xy_autoscale(my_map);
+
+ my_plot.plot(my_map);
+ /*`Finally write the SVG image to a file. */
+ my_plot.write("./auto_2d_plot.svg");
+
+ cout << "X min " << my_plot.x_range().first << ", X max " << my_plot.x_range().second << endl;
+ cout << "Y min " << my_plot.y_range().first << ", Y max " << my_plot.y_range().second << endl;
+
+//] [/auto_2d_plot_2]
+
+ return 0;
+}
+
+/*
+//[auto_2d_plot_output
+
+Output:
+
+auto_2d_plot.cpp
+Linking...
+Embedding manifest...
+Autorun "j:\Cpp\SVG\debug\auto_2d_plot.exe"
+2 goods, 2.1 5.4
+3 goods, 7.3 9.1
+limit value: 99.99 1.#QNAN
+limit value: 999 1.#INF
+limit value: 999.9 1.#INF
+x_min 1.1, x_max 7.3
+y_min 3.2, y_max 9.1
+limits 3
+1 8
+3 10
+Build Time 0:21
+
+
+Linking...
+Embedding manifest...
+Autorun "j:\Cpp\SVG\debug\auto_2d_plot.exe"
+X min 1, X max 8
+Y min 3, Y max 10
+Build Time 0:03
+
+
+//] [/auto_2d_plot_output]
+
+
+Parked pro tem.
+
+
+// double tol100eps = 1000 * numeric_limits<double>::epsilon(); // suitable tight value.
+
+ // double axis_min_value; // Values to be updated by autoscale.
+ // double axis_max_value;
+ // double axis_tick_increment;
+ // int axis_ticks;
+
+ // multiset<double> my_set;
+ //// Initialize my_set with some entirely fictional data.
+ // my_set.insert(1.2);
+ // my_set.insert(2.3);
+ // my_set.insert(3.4);
+
+ // // Feed STL 1D container to scale_axis.
+ // scale_axis(my_set, &axis_min_value, &axis_max_value, &axis_tick_increment, &axis_ticks, false, tol100eps, 6, 0);
+
+*/


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk