---
lang: ja-jp
breaks: true
---
# `Visual Studio Code` で `Polyglot Notebooks`(`.NET Interactive Notebooks`) を使用する。※`ScottPlot.NET`を使用した可視化 2023-02-20
> .NET Interactive Notebooks is now Polyglot Notebooks!
> https://devblogs.microsoft.com/dotnet/dotnet-interactive-notebooks-is-now-polyglot-notebooks/
## Visual Studio Codeに `Polyglot Notebooks` 拡張機能を追加する。


## コマンドパレットより、空のノートブックを追加する




## 使用してみる
> Using DataFrames in Interactive Notebooks
> https://swharden.com/blog/2022-05-01-dotnet-dataframe/#using-dataframes-in-interactive-notebooks
> swharden/Csharp-Data-Visualization
> https://github.com/swharden/Csharp-Data-Visualization/tree/main/projects/dataframe
```csharp=
#r "nuget:Microsoft.Data.Analysis"
using Microsoft.Data.Analysis;
```

`Ctrl` + `Alt` + `Enter` で実行

ノートブックの空いているところで、「+コード」をクリックし、コードセルを追加する。


```csharp=
// load sample data
string[] names = { "Oliver", "Charlotte", "Henry", "Amelia", "Owen" };
int[] ages = { 23, 19, 42, 64, 35 };
double[] heights = { 1.91, 1.62, 1.72, 1.57, 1.85 };
DataFrameColumn[] columns = {
new StringDataFrameColumn("Name", names),
new PrimitiveDataFrameColumn<int>("Age", ages),
new PrimitiveDataFrameColumn<double>("Height", heights),
};
DataFrame df = new(columns);
```

```csharp=
// visualize the dataframe
df
```

```csharp=
// install ScottPlot and register its display type
#r "nuget:ScottPlot"
using Microsoft.DotNet.Interactive.Formatting;
Formatter.Register(typeof(ScottPlot.Plot), (plt, writer) =>
writer.Write(((ScottPlot.Plot)plt).GetImageHTML()), HtmlFormatter.MimeType);
```

```csharp=
// get data as double arrays
double[] ages = Enumerable.Range(0, (int)df.Rows.Count).Select(x => Convert.ToDouble(df["Age"][x])).ToArray();
double[] heights = Enumerable.Range(0, (int)df.Rows.Count).Select(x => Convert.ToDouble(df["Height"][x])).ToArray();
// create and display a plot
var plt = new ScottPlot.Plot(400, 300);
plt.AddScatter(ages, heights);
plt.XLabel("Age");
plt.YLabel("Height");
plt
```

###### tags: `Visual Studio Code` `.NET Interactive Notebooks` `Polyglot Notebooks` `DataFrame` `ScottPlot.NET`