├── ScottPlot.dll ├── media ├── ScottPlot.png ├── RadialChart.png └── SignalChart.png ├── ScottPlotHelper.ps1 ├── README.md └── PSGraphNB.ps1 /ScottPlot.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dfinke/PowerShellScottPlot/HEAD/ScottPlot.dll -------------------------------------------------------------------------------- /media/ScottPlot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dfinke/PowerShellScottPlot/HEAD/media/ScottPlot.png -------------------------------------------------------------------------------- /media/RadialChart.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dfinke/PowerShellScottPlot/HEAD/media/RadialChart.png -------------------------------------------------------------------------------- /media/SignalChart.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dfinke/PowerShellScottPlot/HEAD/media/SignalChart.png -------------------------------------------------------------------------------- /ScottPlotHelper.ps1: -------------------------------------------------------------------------------- 1 | Add-Type -Path .\ScottPlot.dll 2 | 3 | . .\psgraphNB.ps1 4 | 5 | function Show-ScottPlotInNotebook { 6 | param( 7 | $plot, 8 | $DestinationPath 9 | ) 10 | 11 | [void] $plot.SaveFig($DestinationPath) 12 | Show-ImageInNotebook $DestinationPath 13 | Remove-Item $DestinationPath 14 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PowerShell ScottPlot 2 | 3 | Uses Polyglot Interactive Notebooks to demonstrate the capabilities of ScottPlot via PowerShell. 4 | 5 | ## Check out the video 6 | 7 | This walks through creating data visualizations with PowerShell and ScottPlot in the interactive notebook rendering visualizations inline. 8 | 9 | 10 | 11 | ## ScottPlot 12 | 13 | Is a free and [open-source plotting library](https://scottplot.net/) for .NET that makes it easy to interactively display large datasets. 14 | 15 | ![Alt text](media/ScottPlot.png) 16 | 17 | 18 | ## How to run 19 | 20 | - Follow these instructions to setup VS Code and the [Polyglot Interactive Notebooks extension](https://devblogs.microsoft.com/dotnet/polyglot-notebooks-december-2022-release/) 21 | - Clone the repo locally 22 | - Finally, Open the `ScottPlot.ipynb` file in VS Code 23 | 24 | ## Summary 25 | There are two helper PowerShell scripts. 26 | 27 | - ScottPlotHelper.ps1 28 | - Loads the `ScottPlot.dll` and `psgraphNB.ps1` 29 | - Has the `Show-ScottPlotInNotebook` function 30 | - `Show-ScottPlotInNotebook $plt "$pwd\test.png"` 31 | - Takes a ScottPlot plot, and name of the image file to generate 32 | - Generates the image file 33 | - Calls the `Show-ImageInNotebook` function from `psgraphNB.ps1` 34 | - Then removes the image file 35 | 36 | - PSGraphNB.ps1 37 | - Has the `Show-ImageInNotebook` function 38 | - `Show-ImageInNotebook "$pwd\test.png"` 39 | - Takes the name of the image file to display 40 | - Displays the image in the output cell of the notebook 41 | 42 | ## What's in the notebook 43 | 44 | ### A simple way to share Polyglot Notebooks 45 | Check out the rendered notebook and charts here in [nbviewer](https://nbviewer.org/github/dfinke/PowerShellScottPlot/blob/master/ScottPlot.ipynb). 46 | 47 | ### Here's some of what you can do 48 | 49 | ![](media/RadialChart.png) 50 | 51 | ![](media/SignalChart.png) -------------------------------------------------------------------------------- /PSGraphNB.ps1: -------------------------------------------------------------------------------- 1 | using namespace "Microsoft.DotNet.Interactive" 2 | 3 | function Write-Notebook { 4 | # via James O'Neill, in https://github.com/dfinke/PowerShellPivot 5 | <# 6 | .SYNOPSIS 7 | Writes to the output part of the current cell (a streamlined version of Out-Display) 8 | 9 | .PARAMETER Html 10 | Output to be sent as Hmtl 11 | 12 | .PARAMETER Text 13 | Output to be sent as plain text 14 | 15 | .PARAMETER PassThru 16 | If specified returns the output object, allowing it to be updated. 17 | 18 | .EXAMPLE 19 | > $statusMsg = Write-Notebook -PassThru -text "Step 1" 20 | > ... 21 | > $statusmsg.update("Step2") 22 | 23 | Displays and updates text in the current cell output 24 | 25 | .EXAMPLE 26 | > $PSVersionTable | ConvertTo-Html -Fragment | Write-Notebook 27 | 28 | Converts $psversionTable to a table and displays it. Without Write-Notebook the HTML markup would appear. 29 | #> 30 | [cmdletbinding(DefaultParameterSetName = 'Html')] 31 | param ( 32 | [parameter(Mandatory = $true, ParameterSetName = 'Html', ValueFromPipeline = $true, Position = 1 )] 33 | $Html, 34 | 35 | [parameter(Mandatory = $true, ParameterSetName = 'Text')] 36 | $Text, 37 | 38 | [Alias('PT')] 39 | [switch]$PassThru 40 | ) 41 | begin { $htmlbody = @() } 42 | process { if ($html) { $htmlbody += $Html } } 43 | end { 44 | if ($htmlbody.count -gt 0) { $result = [Kernel]::display([Kernel]::HTML($htmlbody), 'text/html') } 45 | if ($Text) { $result = [Kernel]::display($Text, 'text/plain') } 46 | if ($PassThru) { return $result } 47 | } 48 | } 49 | 50 | function Show-ImageInNotebook { 51 | param( 52 | $DestinationPath 53 | ) 54 | 55 | $png = [System.IO.File]::ReadAllBytes($DestinationPath) 56 | $b64 = [System.Convert]::ToBase64String($png) 57 | 58 | $img = '' -f $b64 59 | 60 | Write-Notebook -Html $img 61 | } --------------------------------------------------------------------------------