Eto , Windows chart or oxyplot?

Ok here it is:

This is how you run a Wpf window with Python

import clr

basePath = "c:\\path\\to\\your\\lib\\folder\\"


clr.AddReferenceToFileAndPath(basePath + "OxyPlot.dll")
clr.AddReferenceToFileAndPath(basePath + "OxyPlot.Wpf.dll")
clr.AddReferenceToFileAndPath(basePath + "OxyPlotExample.exe")

from OxyPlotExample import MainWindow
import System.Windows as sw
import Rhino
import OxyPlot as oxy
import System
from System.Collections.Generic import List

exWnd = MainWindow(); 
# Populate with example points
exWnd.DrawExample(50)

# Create a series from Rhino and pass it over
list = List[oxy.DataPoint]()
list.Add(oxy.DataPoint(1,5))
list.Add(oxy.DataPoint(1,6))
list.Add(oxy.DataPoint(1,7))
list.Add(oxy.DataPoint(1,8))
exWnd.Draw(list)  

exWnd.ShowDialog()

In Visual Studio create a WPF Application targeting Net Framework 4.5 (not Core!!!).
Get the nuget package OxyPlot.Wpf (downloads OxyPlot.Core).

Modify the MainWindow.xaml

<Window x:Class="OxyPlotExample.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:OxyPlotExample"
        xmlns:oxy="http://oxyplot.org/wpf"
        mc:Ignorable="d"
        Title="Oxy Plot Example" Height="450" Width="800">
    <Grid>
        <oxy:PlotView x:Name="_plotView"></oxy:PlotView>
    </Grid>
</Window>

And in the codebehind MainWindow.cs

using OxyPlot;
using OxyPlot.Axes;
using OxyPlot.Series;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace OxyPlotExample
{
    /// <summary>
    /// Interaktionslogik für MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        private PlotModel _model;

        public MainWindow()
        {
            InitializeComponent();
            InitOxy();
            //DrawExample(30);
        }
        /// <summary>
        /// Initializes Oxyplot (Non-MVVM)
        /// </summary>
        private void InitOxy()
        {           
            _model = new OxyPlot.PlotModel();
            _model.Axes.Add(new LinearAxis() { Title = "X", Minimum = 0.0, Maximum = 10.0 });
            _model.Axes.Add(new LinearAxis() { Title = "Y", Minimum = 0.0, Maximum = 10.0 });              
            _plotView.Model = _model;
            DrawExample(50);
        }

        public void Draw(IEnumerable<DataPoint> points)
        {
            var series = new LineSeries(); // cache it if frequently changed
            series.Points.AddRange(points);
            _model.Series.Add(series);
            _model.InvalidatePlot(true); // Redraw
        }

        public void DrawExample(int n)
        {
            DataPoint[] points = new DataPoint[n];
            Random rnd = new Random(42);
            for (int i = 0; i < n; i++)
            {
                points[i] = new DataPoint(i*0.1, rnd.NextDouble() * 10);
            }
            Draw(points);

        }

    }
}

And compile… Don’t forget to reference the path to these files in the Python script.
If you don’t want to do the VS part, take the following example compilation:

example_bins.zip (382.0 KB)

2 Likes