Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XPlot in a C# .NET Console App (not a jupyter notebook) #143

Open
CBrauer opened this issue Jun 11, 2020 · 3 comments
Open

XPlot in a C# .NET Console App (not a jupyter notebook) #143

CBrauer opened this issue Jun 11, 2020 · 3 comments

Comments

@CBrauer
Copy link

CBrauer commented Jun 11, 2020

Hey,
Great work on XPlot.

Any plans to support XPlot in a C# Console App (not a jupyter notebook)?
I get a plot window, with the following code, but no data is drawn.

    using System;
    using System.Collections.Generic;
    using System.Diagnostics;
    using System.IO;
    using System.Linq;
    using Microsoft.ML;
    using Microsoft.ML.AutoML;
    using Microsoft.ML.Data;
    using Microsoft.ML.Featurizers;
    using Tensorflow;
    using XPlot.Plotly;

    namespace BottleRocketClassify {
        internal static class Program {
            public static class ModelBuilder {
                public static void Run() {
                    var mlContext = new MLContext(seed: 1);

                    var trainDataView = mlContext.Data.LoadFromTextFile<ModelInput>(
                        path: @"../../../data/train.csv",
                        hasHeader: true,
                        separatorChar: ',');

                    int numberOfRows = 1000;
                    var boxRatio = 
                        trainDataView.GetColumn<float>("BoxRatio").Take(numberOfRows).ToArray();

                    var data = boxRatio.Cast<float>();
                    var chart = new PlotlyChart();
                    Chart.Bar(data);
                    Chart.Show(chart);
                }
            }
        }
    }

Charles

@malisimo
Copy link

malisimo commented Sep 1, 2020

Hi CBrauer, use of XPlot within C# console apps should certainly be supported.
Rather than calling Chart.Show on your newly constructed PlotlyChart, please try the following instead:

Chart.Bar(data).Show();

As a minimal test, the following could be used:

using System.Linq;
using XPlot.Plotly;

namespace XPlotTest
{
    class Program
    {
        static void Main(string[] args)
        {
            var data = Enumerable.Range(0,100).Select(v => v+.0);
            Chart.Bar(data).Show();
        }
    }
}

This is to replace Program.cs generated using:

dotnet new console -n XPlotTest
cd XPlotTest
dotnet add package XPlot.Plotly
dotnet add package FSharp.Core

All seems fine on my machine (TM)!

@aherrick
Copy link

as a note i had to also install newtonsoft json, but other than that this worked perfectly!

@MaxBernstetter
Copy link

MaxBernstetter commented Mar 10, 2021

Hey @malisimo , thx for the answer! Could you maybe provide a C# syntax example on how to draw a line chart, containing two data series?

var data = list1.Zip(list2, (a,b) => Tuple.Create(a,b));
Chart.Line<int,int>(data).Show();

This syntax only shows one line...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants