{ "cells": [ { "attachments": {}, "cell_type": "markdown", "metadata": { "dotnet_interactive": { "language": "pwsh" }, "polyglot_notebook": { "kernelName": "pwsh" } }, "source": [ "# PowerShell ScottPlot\n", "\n", "https://github.com/dfinke/PowerShellScottPlot" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "dotnet_interactive": { "language": "pwsh" }, "polyglot_notebook": { "kernelName": "pwsh" }, "vscode": { "languageId": "polyglot-notebook" } }, "outputs": [], "source": [ ". .\\ScottPlotHelper.ps1" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": { "dotnet_interactive": { "language": "pwsh" }, "polyglot_notebook": { "kernelName": "pwsh" } }, "source": [ "## Create three ScottPlot charts\n", "- Bubble chart\n", "- Scatter chart\n", "- Bar chart" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "dotnet_interactive": { "language": "pwsh" }, "polyglot_notebook": { "kernelName": "pwsh" }, "vscode": { "languageId": "polyglot-notebook" } }, "outputs": [ { "data": { "text/html": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "[double[]] $dataX = 1, 2, 3, 4, 5\n", "[double[]] $dataY = 1, 4, 9, 16, 25 \n", "\n", "'AddBubblePlot', 'AddScatter', 'AddBar' | ForEach-Object {\n", " $plt = [ScottPlot.Plot]::new(400, 300)\n", " [Void] $plt.$_($dataX, $dataY)\n", "\n", " Show-ScottPlotInNotebook $plt \"$pwd\\$_.png\"\n", "}" ] }, { "cell_type": "markdown", "metadata": { "dotnet_interactive": { "language": "csharp" }, "polyglot_notebook": { "kernelName": "csharp" } }, "source": [ "## Pie Chart" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "dotnet_interactive": { "language": "pwsh" }, "vscode": { "languageId": "polyglot-notebook" } }, "outputs": [ { "data": { "text/html": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "$plt = [ScottPlot.Plot]::new(600, 400)\n", "\n", "[double[]] $values = 778, 283, 184, 76, 43\n", "[void]$plt.AddPie($values)\n", "\n", "Show-ScottPlotInNotebook $plt \"PieChart.png\"" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": { "dotnet_interactive": { "language": "csharp" }, "polyglot_notebook": { "kernelName": "csharp" } }, "source": [ "## Exploded Pie Chart" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "dotnet_interactive": { "language": "pwsh" }, "vscode": { "languageId": "polyglot-notebook" } }, "outputs": [ { "data": { "text/html": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "$plt = [ScottPlot.Plot]::new(600, 400)\n", "\n", "[double[]] $values = 778, 283, 184, 76, 43\n", "$pie = $plt.AddPie($values)\n", "$pie.Explode = $true\n", "\n", "Show-ScottPlotInNotebook $plt \"PieChart.png\"" ] }, { "cell_type": "markdown", "metadata": { "dotnet_interactive": { "language": "csharp" }, "polyglot_notebook": { "kernelName": "csharp" } }, "source": [ "## Signal Chart" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "dotnet_interactive": { "language": "pwsh" }, "vscode": { "languageId": "polyglot-notebook" } }, "outputs": [ { "data": { "text/html": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "$plt = [ScottPlot.Plot]::new(600, 400)\n", "\n", "[double[]] $values = [ScottPlot.DataGen]::RandomWalk(1000000)\n", "[void]$plt.AddSignal($values, 48000)\n", "$plt.Title(\"One Million Points\", $false, 'Black', $null, 'Arial')\n", "\n", "Show-ScottPlotInNotebook $plt \"quickstart_signal.png\"" ] }, { "cell_type": "markdown", "metadata": { "dotnet_interactive": { "language": "csharp" }, "polyglot_notebook": { "kernelName": "csharp" } }, "source": [ "## Scatter Chart" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "dotnet_interactive": { "language": "pwsh" }, "vscode": { "languageId": "polyglot-notebook" } }, "outputs": [ { "data": { "text/html": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "$plt = [ScottPlot.Plot]::new(600, 400)\n", "\n", "# sample data\n", "[double[]] $xs = [ScottPlot.DataGen]::Consecutive(51)\n", "[double[]] $sin = [ScottPlot.DataGen]::Sin(51)\n", "[double[]] $cos = [ScottPlot.DataGen]::Cos(51)\n", "\n", "[void]$plt.AddScatter($xs, $sin)\n", "[void]$plt.AddScatter($xs, $cos)\n", "\n", "$plt.Title(\"Scatter Plot\", $false, 'Black', $null, 'Arial')\n", "$plt.XLabel(\"Horizontal Axis\")\n", "$plt.YLabel(\"Vertical Axis\")\n", "\n", "Show-ScottPlotInNotebook $plt \"quickstart_scatter.png\"\n" ] }, { "cell_type": "markdown", "metadata": { "dotnet_interactive": { "language": "csharp" }, "polyglot_notebook": { "kernelName": "csharp" } }, "source": [ "## Coxcomb Chart" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "dotnet_interactive": { "language": "pwsh" }, "vscode": { "languageId": "polyglot-notebook" } }, "outputs": [ { "data": { "text/html": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "$plt = [ScottPlot.Plot]::new(600, 400)\n", "\n", "[double[]] $values = 11, 16, 7, 3, 14\n", "$coxcomb = $plt.AddCoxcomb($values)\n", "$coxcomb.FillColors = $plt.Palette.GetColors(5, 0, .5);\n", "$coxcomb.SliceLabels = \"bikes\", \"blimps\", \"subs\", \"saucers\", \"rockets\"\n", "\n", "Show-ScottPlotInNotebook $plt \"quickstart_coxcomb.png\"\n" ] }, { "cell_type": "markdown", "metadata": { "dotnet_interactive": { "language": "csharp" }, "polyglot_notebook": { "kernelName": "csharp" } }, "source": [ "## Polygons Chart" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "dotnet_interactive": { "language": "pwsh" }, "vscode": { "languageId": "polyglot-notebook" } }, "outputs": [ { "data": { "text/html": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "$plt = [ScottPlot.Plot]::new(600, 400)\n", "\n", "[double[]] $xs1 = 2, 8, 6, 4\n", "[double[]] $ys1 = 3, 4, 0.5, 1\n", "[void]$plt.AddPolygon($xs1, $ys1);\n", "\n", "[double[]] $xs2 = 3, 2.5, 5\n", "[double[]] $ys2 = 4.5, 1.5, 2.5\n", "[void]$plt.AddPolygon($xs2, $ys2, $plt.GetNextColor(.5), 2)\n", "\n", "Show-ScottPlotInNotebook $plt \"quickstart_polygon.png\"" ] }, { "cell_type": "markdown", "metadata": { "dotnet_interactive": { "language": "csharp" }, "polyglot_notebook": { "kernelName": "csharp" } }, "source": [ "## Radial Chart" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "dotnet_interactive": { "language": "pwsh" }, "vscode": { "languageId": "polyglot-notebook" } }, "outputs": [ { "data": { "text/html": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "$plt = [ScottPlot.Plot]::new(600, 400)\n", "\n", "[double[]] $values = 100, 80, 65, 45, 20\n", "[void]$plt.AddRadialGauge($values)\n", "\n", "Show-ScottPlotInNotebook $plt \"radialgauge_quickstart.png\"" ] }, { "cell_type": "markdown", "metadata": { "dotnet_interactive": { "language": "csharp" }, "polyglot_notebook": { "kernelName": "csharp" } }, "source": [ "## Text Chart" ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "dotnet_interactive": { "language": "pwsh" }, "vscode": { "languageId": "polyglot-notebook" } }, "outputs": [ { "data": { "text/html": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "$plt = [ScottPlot.Plot]::new(600, 400)\n", "\n", "$pointCount = 51\n", "[double[]] $x = [ScottPlot.DataGen]::Consecutive($pointCount)\n", "[double[]] $sin = [ScottPlot.DataGen]::Sin($pointCount)\n", "[double[]] $cos = [ScottPlot.DataGen]::Cos($pointCount)\n", "\n", "[void]$plt.AddScatter($x, $sin)\n", "[void]$plt.AddScatter($x, $cos)\n", "\n", "[void]$plt.AddText(\"sample text\", 10, .5, 16, 'Blue')\n", "\n", "Show-ScottPlotInNotebook $plt \"text_quickstart.png\"" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": { "dotnet_interactive": { "language": "pwsh" }, "polyglot_notebook": { "kernelName": "pwsh" } }, "source": [ "# Histogram" ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "dotnet_interactive": { "language": "pwsh" }, "vscode": { "languageId": "polyglot-notebook" } }, "outputs": [ { "data": { "text/html": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "$plt = [ScottPlot.Plot]::new(600, 400)\n", "$rand = [System.Random]::new(0)\n", "$values = [ScottPlot.DataGen]::RandomNormal($rand, 1234, 178.4, 7.6)\n", "\n", "# create a histogram\n", "$min = 140\n", "$histogram = [ScottPlot.Statistics.Common]::Histogram($values, $min, 220, 1)\n", "$counts = $histogram.Item1\n", "$leftEdges = $histogram.Item2\n", "$leftEdges=$leftEdges[1..($leftEdges.count - 1)]\n", "\n", "\n", "$bar = $plt.AddBar($counts, $leftEdges, [System.Drawing.Color]::Blue)\n", "$bar.BarWidth = 1\n", "\n", "# # customize the plot style\n", "[void]$plt.YAxis.Label(\"Count (#)\")\n", "[void]$plt.XAxis.Label(\"Height (cm)\")\n", "[void]$plt.SetAxisLimits($min)\n", "\n", "Show-ScottPlotInNotebook $plt \"stats_histogram.png\"\n" ] }, { "cell_type": "markdown", "metadata": { "dotnet_interactive": { "language": "pwsh" }, "polyglot_notebook": { "kernelName": "pwsh" } }, "source": [ "# Grouping" ] }, { "cell_type": "code", "execution_count": 12, "metadata": { "dotnet_interactive": { "language": "pwsh" }, "vscode": { "languageId": "polyglot-notebook" } }, "outputs": [ { "data": { "text/html": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "$plt = [ScottPlot.Plot]::new(600, 400)\n", "$groupCount = 5\n", "$rand = [System.Random]::new(0)\n", "$values1 = [ScottPlot.DataGen]::RandomNormal($rand, $groupCount, 20, 5)\n", "$values2 = [ScottPlot.DataGen]::RandomNormal($rand, $groupCount, 20, 5)\n", "$values3 = [ScottPlot.DataGen]::RandomNormal($rand, $groupCount, 20, 5)\n", "$errors1 = [ScottPlot.DataGen]::RandomNormal($rand, $groupCount, 5, 2)\n", "$errors2 = [ScottPlot.DataGen]::RandomNormal($rand, $groupCount, 5, 2)\n", "$errors3 = [ScottPlot.DataGen]::RandomNormal($rand, $groupCount, 5, 2)\n", "\n", "$groupNames = \"Group A\", \"Group B\", \"Group C\", \"Group D\", \"Group E\" \n", "$seriesNames = \"Series 1\", \"Series 2\", \"Series 3\" \n", "$valuesBySeries = $values1, $values2, $values3 \n", "$errorsBySeries = $errors1, $errors2, $errors3 \n", "[void]$plt.AddBarGroups($groupNames, $seriesNames, $valuesBySeries, $errorsBySeries);\n", "[void]$plt.Legend($true, [ScottPlot.Alignment]::UpperRight)\n", "\n", "Show-ScottPlotInNotebook $plt \"bar_group.png\"" ] }, { "cell_type": "markdown", "metadata": { "dotnet_interactive": { "language": "csharp" }, "polyglot_notebook": { "kernelName": "csharp" } }, "source": [ "## Frameless Plot" ] }, { "cell_type": "code", "execution_count": 13, "metadata": { "dotnet_interactive": { "language": "pwsh" }, "vscode": { "languageId": "polyglot-notebook" } }, "outputs": [ { "data": { "text/html": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "$plt = [ScottPlot.Plot]::new(600, 400)\n", "\n", "$n=51\n", "[void]$plt.AddSignal([ScottPlot.DataGen]::Sin($n))\n", "[void]$plt.AddSignal([ScottPlot.DataGen]::Cos($n))\n", "# $plt.Style(figureBackground: Color.SkyBlue)\n", "\n", "[void]$plt.Frameless()\n", "\n", "Show-ScottPlotInNotebook $plt \"layout_frameless.png\"" ] } ], "metadata": { "kernelspec": { "display_name": ".NET (C#)", "language": "C#", "name": ".net-csharp" }, "polyglot_notebook": { "kernelInfo": { "defaultKernelName": "csharp", "items": [ { "aliases": [ "c#", "C#" ], "languageName": "C#", "name": "csharp" }, { "aliases": [ "frontend" ], "name": "vscode" }, { "aliases": [], "name": ".NET" }, { "aliases": [ "f#", "F#" ], "languageName": "F#", "name": "fsharp" }, { "aliases": [], "languageName": "HTML", "name": "html" }, { "aliases": [ "js" ], "languageName": "JavaScript", "name": "javascript" }, { "aliases": [], "languageName": "KQL", "name": "kql" }, { "aliases": [], "languageName": "Mermaid", "name": "mermaid" }, { "aliases": [ "powershell" ], "languageName": "PowerShell", "name": "pwsh" }, { "aliases": [], "languageName": "SQL", "name": "sql" }, { "aliases": [], "name": "value" }, { "aliases": [], "name": "webview" } ] } } }, "nbformat": 4, "nbformat_minor": 2 }