Skip to content

Commit e69aaa5

Browse files
committed
Add Image docs
1 parent b29a51b commit e69aaa5

2 files changed

Lines changed: 131 additions & 0 deletions

File tree

Plotly.NET.sln

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "docs", "docs", "{7B09CC0A-F
5858
docs\02_5_pie-doughnut-charts.fsx = docs\02_5_pie-doughnut-charts.fsx
5959
docs\02_6_table.fsx = docs\02_6_table.fsx
6060
docs\02_7_heatmaps.fsx = docs\02_7_heatmaps.fsx
61+
docs\02_8_Images.fsx = docs\02_8_Images.fsx
6162
docs\03_0_3d-scatter-plots.fsx = docs\03_0_3d-scatter-plots.fsx
6263
docs\03_1_3d-surface-plots.fsx = docs\03_1_3d-surface-plots.fsx
6364
docs\03_2_3d-mesh-plots.fsx = docs\03_2_3d-mesh-plots.fsx

docs/02_8_Images.fsx

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
(**
2+
---
3+
title: Images
4+
category: Simple Charts
5+
categoryindex: 3
6+
index: 9
7+
---
8+
*)
9+
10+
(*** hide ***)
11+
12+
(*** condition: prepare ***)
13+
#r "nuget: Newtonsoft.JSON, 12.0.3"
14+
#r "nuget: DynamicObj"
15+
#r "../bin/Plotly.NET/netstandard2.0/Plotly.NET.dll"
16+
17+
(*** condition: ipynb ***)
18+
#if IPYNB
19+
#r "nuget: Plotly.NET, {{fsdocs-package-version}}"
20+
#r "nuget: Plotly.NET.Interactive, {{fsdocs-package-version}}"
21+
#endif // IPYNB
22+
23+
(**
24+
# Images
25+
26+
[![Binder]({{root}}img/badge-binder.svg)](https://mybinder.org/v2/gh/plotly/Plotly.NET/gh-pages?filepath={{fsdocs-source-basename}}.ipynb) 
27+
[![Script]({{root}}img/badge-script.svg)]({{root}}{{fsdocs-source-basename}}.fsx) 
28+
[![Notebook]({{root}}img/badge-notebook.svg)]({{root}}{{fsdocs-source-basename}}.ipynb)
29+
30+
*Summary:* This example shows how to create image charts in F#.
31+
32+
There are multiple ways of generating image charts:
33+
- From 3 Dimensional color collections, where the inner arrays contain 3 (color dimensions without alpha channel) or 4 (color dimensions and alpha channel) values. The color model can be set separately as shown below.
34+
- From a 2 dimensional collection Plotly.NETs `ARGB` type that represents rgba values
35+
- From a base64 encoded image data source
36+
37+
## Creating Image charts from raw color arrays
38+
*)
39+
40+
// 3d collection containing color values
41+
open Plotly.NET
42+
43+
let colors = [
44+
[[0 ;0 ;255]; [255;255;0 ]; [0 ;0 ;255]]
45+
[[255;0 ;0 ]; [255;0 ;255]; [255;0 ;255]]
46+
[[0 ;255;0 ]; [0 ;255;255]; [255;0 ;0 ]]
47+
]
48+
49+
let imageRaw =
50+
Chart.Image(Z=colors)
51+
|> Chart.withTitle "Image chart from raw color component arrays"
52+
53+
(*** condition: ipynb ***)
54+
#if IPYNB
55+
imageRaw
56+
#endif // IPYNB
57+
58+
(***hide***)
59+
imageRaw |> GenericChart.toChartHTML
60+
(***include-it-raw***)
61+
62+
(**
63+
To change the color model to HSL for example, add the `ColorModel` argument:
64+
*)
65+
66+
let imageRawHSL =
67+
Chart.Image(Z=colors, ColorModel=StyleParam.ColorModel.HSL)
68+
|> Chart.withTitle "HSL color model"
69+
70+
(*** condition: ipynb ***)
71+
#if IPYNB
72+
imageRawHSL
73+
#endif // IPYNB
74+
75+
(***hide***)
76+
imageRawHSL |> GenericChart.toChartHTML
77+
(***include-it-raw***)
78+
79+
(**
80+
## Creating Image charts from ARGB arrays
81+
82+
Note that this way of creating image charts uses the RGBA color model.
83+
*)
84+
85+
let argbs = [
86+
[ColorKeyword.AliceBlue ; ColorKeyword.CornSilk ; ColorKeyword.LavenderBlush ] |> List.map ARGB.fromKeyword
87+
[ColorKeyword.DarkGray ; ColorKeyword.Snow ; ColorKeyword.MidnightBlue ] |> List.map ARGB.fromKeyword
88+
[ColorKeyword.LightSteelBlue; ColorKeyword.DarkKhaki; ColorKeyword.LightAkyBlue ] |> List.map ARGB.fromKeyword
89+
]
90+
91+
let imageARGB =
92+
Chart.Image(argbs)
93+
|> Chart.withTitle "ARGB image chart"
94+
95+
(*** condition: ipynb ***)
96+
#if IPYNB
97+
imageARGB
98+
#endif // IPYNB
99+
100+
(***hide***)
101+
imageARGB |> GenericChart.toChartHTML
102+
(***include-it-raw***)
103+
104+
(**
105+
## Creating Image charts from base64 encoded images
106+
*)
107+
open System
108+
open System.IO
109+
110+
let imageSource = $@"{__SOURCE_DIRECTORY__}/img/logo.png"
111+
112+
let base64String =
113+
imageSource
114+
|> File.ReadAllBytes
115+
|> System.Convert.ToBase64String
116+
117+
let logoImage =
118+
Chart.Image(
119+
Source=($"data:image/jpg;base64,{base64String}")
120+
)
121+
|> Chart.withTitle "This is Plotly.NET:"
122+
123+
(*** condition: ipynb ***)
124+
#if IPYNB
125+
logoImage
126+
#endif // IPYNB
127+
128+
(***hide***)
129+
logoImage |> GenericChart.toChartHTML
130+
(***include-it-raw***)

0 commit comments

Comments
 (0)