Discrete Colors in F#
How to use and configure discrete color sequences, also known as categorical or qualitative color scales.
Plotly is known for its graphing libraries, but it's also a broader ecosystem for building interactive data apps, AI data analysis tools, and deploying and hosting Dash apps. Explore the full set of tools and platforms designed to help turn data into action. Discover Plotly.
Note: We are retiring documentation for R, MATLAB, Julia, and F#. Learn more about this change here.
#r "nuget: Plotly.NET, 2.0.0-preview.8"
#r "nuget: Plotly.NET.Interactive, 2.0.0-preview.8"
#r "nuget: Deedle"
#r "nuget: FSharp.Data"
color can be used to represent continuous or discrete data. Marker Color can be used to set discrete colors to individual points as shown in the below example. This page is about using color to represent categorical data using discrete colors, but Plotly.NET can also represent continuous values with color.
open Deedle
open FSharp.Data
open Plotly.NET
let data=
Http.RequestString "https://raw.githubusercontent.com/plotly/datasets/master/tips.csv"
|> fun csv -> Frame.ReadCsvString(csv,true,separators=",")
let getColumnData column=
data
|> Frame.getCol column
|> Series.values
|> Array.ofSeq
let x = [1.; 2.; 3.; 4.; 5.; 6.; 7.; 8.; 9.; 10.; ]
let y = [2.; 1.5; 5.; 1.5; 3.; 2.5; 2.5; 1.5; 3.5; 1.]
let colors = ["red"; "magenta"; "yellow"; "blue"; "deeppink";
"orangered"; "black"; "gray"; "aliceblue"; "cyan"]
|> Seq.map (fun c -> Color.fromString c)
|> Color.fromColors
Chart.Point(x,y,Name="line",Color=colors)
open Plotly.NET.TraceObjects
let x=[1; 2; 3; 4]
let y=[10; 11; 12; 13]
let colors =
["rgb(160, 164, 214)"; "rgb(255, 144, 14)"; "rgb(44, 160, 101)"; "rgb(255, 65, 54)"]
|> Seq.map (fun c -> Color.fromString(c))
|> Color.fromColors
let marker = Marker.init(Color=colors)
Chart.Scatter(x,y,StyleParam.Mode.Markers)
|> Chart.withMarker(marker)