Exemple #1
0
        /// <summary>
        /// Merges the this object and the given data set
        /// <paramref name="other"/> into a new data set (while making a deep
        /// copy of the data)
        /// </summary>
        /// <param name="other">
        /// The data set to be merged into this one
        /// </param>
        /// <returns>
        /// A data set containing all data in this object and
        /// <paramref name="other"/>
        /// </returns>
        public Plot2Ddata Merge(Plot2Ddata other)
        {
            if (this.LogX != other.LogX || this.LogY != other.LogY)
            {
                throw new Exception("Data sets have incompatible logarithmic scaling options");
            }

            IList <XYvalues> mergedGroups = new List <XYvalues>(this.dataGroups.Length + other.dataGroups.Length);

            mergedGroups.AddRange(this.dataGroups.Select(g => g.CloneAs()));
            foreach (XYvalues otherGroup in other.dataGroups)
            {
                if (this.dataGroups.Any(g => g.Name == otherGroup.Name))
                {
                    throw new NotSupportedException(String.Format(
                                                        "Group key '{0}' exists in both data sets. This is not supported.",
                                                        otherGroup.Name));
                }

                mergedGroups.Add(otherGroup.CloneAs());
            }

            Plot2Ddata result = new Plot2Ddata(mergedGroups.ToArray());

            result.LogX = this.LogX;
            result.LogY = this.LogY;
            return(result);
        }
Exemple #2
0
        /// <summary>
        /// Creates a new data set where <see cref="LogY"/> is to true. Useful
        /// for command chaining on the console.
        /// </summary>
        /// <returns>
        /// A copy of this object where <see cref="LogY"/> equals true.
        /// </returns>
        public Plot2Ddata WithLogY()
        {
            var set = new Plot2Ddata(this);

            set.LogY = true;
            return(set);
        }
Exemple #3
0
 /// <summary>
 /// Copy constructor
 /// </summary>
 /// <param name="originalSet">
 /// Object to be copied from.
 /// </param>
 private Plot2Ddata(Plot2Ddata originalSet)
     : this()
 {
     this.dataGroups = originalSet.dataGroups;
     this.LogX       = originalSet.LogX;
     this.LogY       = originalSet.LogY;
 }
Exemple #4
0
        /// <summary>
        /// Single plot window:
        /// Converts <see cref="Plot2Ddata"/> into an alive Gnuplot object.
        /// </summary>
        public static Gnuplot ToGnuplot(this Plot2Ddata _2DData, GnuplotPageLayout layout = null)
        {
            if (layout != null)
            {
                throw new NotImplementedException("todo");
            }

            Gnuplot gp = new Gnuplot();

            _2DData.ToGnuplot(gp);
            return(gp);
        }
Exemple #5
0
 /// <summary>
 /// Gnuplot plotting (single plot), automatic choice of gnuplot driver depending on
 /// the current value of <see cref="UseCairoLatex"/>.
 /// </summary>
 public static object PlotNow(this Plot2Ddata _2DData)
 {
     using (Gnuplot gp = _2DData.ToGnuplot()) {
         if (UseCairoLatex)
         {
             return(gp.PlotCairolatex());
         }
         else
         {
             return(gp.PlotGIF());
         }
     }
 }
Exemple #6
0
        /// <summary>
        /// Creates an xy-plot form a table
        /// </summary>
        /// <param name="Tab"></param>
        /// <param name="RowSelector">
        /// Selects, which table row will end up in which graph, resp. data group (<see cref="Plot2Ddata.dataGroups"/>).
        /// If the returned name is null, or if an exception is thrown, the respective data row will not be included in any graph.
        /// </param>
        /// <param name="NoOfSweeps">
        /// To sweep over the table multiple times, e.g. for selecting more than one value per row.
        /// </param>
        /// <returns></returns>
        public static Plot2Ddata ToPlot(this DataTable Tab,
                                        PlotRowSelectorEx RowSelector, int NoOfSweeps)
        {
            Plot2Ddata ret = new Plot2Ddata();


            // loop over table rows
            // ====================
            for (int iSweep = 0; iSweep < NoOfSweeps; iSweep++)
            {
                string[] ColNames = Tab.GetColumnNames();
                int      L        = Tab.Rows.Count;
                int      J        = Tab.Columns.Count;
                for (int i = 0; i < L; i++)
                {
                    DataRow orgRow = Tab.Rows[i];
                    Dictionary <string, object> orgRowAsDict = new Dictionary <string, object>();
                    foreach (string ColName in ColNames)
                    {
                        object obj_ColName = orgRow[ColName];
                        if (obj_ColName == DBNull.Value)
                        {
                            orgRowAsDict.Add(ColName, null);
                        }
                        else
                        {
                            orgRowAsDict.Add(ColName, obj_ColName);
                        }
                    }

                    string groupName;
                    Solution.Gnuplot.PlotFormat graphFormat;
                    double xValue;
                    double yValue;
                    try {
                        RowSelector(iSweep, i, orgRowAsDict, out groupName, out graphFormat, out xValue, out yValue);
                    } catch (Exception e) {
                        Console.WriteLine("Exception in the selection test of row {0}: {1}, Message: {2}.", i, e.GetType().Name, e.Message);
                        groupName   = null;
                        graphFormat = null;
                        xValue      = 0.0;
                        yValue      = 0.0;
                    }

                    if (groupName != null)
                    {
                        //double xValue = Convert.ToDouble(orgRowAsDict[ColName_ForXValues]);
                        //double yValue = Convert.ToDouble(orgRowAsDict[ColName_ForYValues]);

                        Plot2Ddata.XYvalues xyGroup = Array.Find(ret.dataGroups, xyG => xyG.Name.Equals(groupName));
                        if (xyGroup == null)
                        {
                            xyGroup = new Plot2Ddata.XYvalues(groupName);
                            ArrayTools.AddToArray(xyGroup, ref ret.dataGroups);
                        }

                        ArrayTools.AddToArray(xValue, ref xyGroup.Abscissas);
                        ArrayTools.AddToArray(yValue, ref xyGroup.Values);

                        xyGroup.Format = graphFormat;
                    }
                }
            }

            // sort data
            // =========
            foreach (var xyGroup in ret.dataGroups)
            {
                Array.Sort(xyGroup.Abscissas, xyGroup.Values);
            }


            // return
            // ======
            return(ret);
        }
Exemple #7
0
        /// <summary>
        /// Creates an xy-plot form a table
        /// </summary>
        /// <param name="Tab"></param>
        /// <param name="ColName_ForXValues">
        /// Column name, where the values for the x-axis are taken.
        /// </param>
        /// <param name="ColName_ForYValues"></param>
        /// <param name="ColName_GroupSelection">
        /// Selects, which table row will end up in which graph, resp. data group (<see cref="Plot2Ddata.dataGroups"/>).
        /// </param>
        /// <returns></returns>
        public static Plot2Ddata ToPlot(this DataTable Tab,
                                        string ColName_ForXValues, string ColName_ForYValues,
                                        params string[] ColName_GroupSelection)
        {
            Plot2Ddata ret = new Plot2Ddata();

            // loop over table rows
            // ====================
            string[] ColNames = Tab.GetColumnNames();
            int      L        = Tab.Rows.Count;
            int      J        = Tab.Columns.Count;

            for (int i = 0; i < L; i++)
            {
                DataRow orgRow = Tab.Rows[i];
                Dictionary <string, object> orgRowAsDict = new Dictionary <string, object>();
                foreach (string ColName in ColNames)
                {
                    object obj_ColName = orgRow[ColName];
                    if (obj_ColName == DBNull.Value)
                    {
                        orgRowAsDict.Add(ColName, null);
                    }
                    else
                    {
                        orgRowAsDict.Add(ColName, obj_ColName);
                    }
                }

                string groupName = "";
                try {
                    //groupName = GroupSelector(i, orgRowAsDict);

                    for (int iS = 0; iS < ColName_GroupSelection.Length; iS++)
                    {
                        groupName += ColName_GroupSelection[iS] + orgRow[ColName_GroupSelection[iS]].ToString();
                        if (iS < ColName_GroupSelection.Length - 1)
                        {
                            groupName += "--";
                        }
                    }
                } catch (Exception e) {
                    Console.WriteLine("Exception in the selection test of row {0}: {1}, Message: {2}.", i, e.GetType().Name, e.Message);
                    groupName = null;
                }

                if (groupName != null)
                {
                    double xValue = Convert.ToDouble(orgRowAsDict[ColName_ForXValues]);
                    double yValue = Convert.ToDouble(orgRowAsDict[ColName_ForYValues]);

                    Plot2Ddata.XYvalues xyGroup = Array.Find(ret.dataGroups, xyG => xyG.Name.Equals(groupName));
                    if (xyGroup == null)
                    {
                        xyGroup = new Plot2Ddata.XYvalues(groupName);
                        ArrayTools.AddToArray(xyGroup, ref ret.dataGroups);
                    }

                    ArrayTools.AddToArray(xValue, ref xyGroup.Abscissas);
                    ArrayTools.AddToArray(yValue, ref xyGroup.Values);
                }
            }

            // sort data
            // =========
            foreach (var xyGroup in ret.dataGroups)
            {
                Array.Sort(xyGroup.Abscissas, xyGroup.Values);
            }


            // return
            // ======
            return(ret);
        }