Skip to content

Contours should be accessible for PointDensity charts #426

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
bvenn opened this issue Oct 12, 2023 · 1 comment
Closed

Contours should be accessible for PointDensity charts #426

bvenn opened this issue Oct 12, 2023 · 1 comment
Labels
Area: Core API Area: MissingAbstraction Plotly.js functionality that has to be implemented

Comments

@bvenn
Copy link
Collaborator

bvenn commented Oct 12, 2023

Description

I tried to combine two point density charts that share their coloraxis. For heatmaps this does not seems to be a problem, but for point density charts you have to (i) align the coloraxis, and (ii) set the contours individually.

Repro steps

code
#r "nuget: Plotly.NET.Interactive"

open Plotly.NET
open Plotly.NET.LayoutObjects
open Plotly.NET.TraceObjects
open Plotly.NET.StyleParam

let getZeroCollection n : float []=
    Array.zeroCreate n 

[
    Chart.PointDensity(
        x=(getZeroCollection 100),
        y=(getZeroCollection 100)
    ) 
    |> Chart.withColorAxisAnchor(1)

    Chart.PointDensity(
        x = (getZeroCollection 50),
        y = (getZeroCollection 50)
    ) 
    |> Chart.withColorAxisAnchor(1)
]
|> Chart.Grid(2,1)

image

The inner circle of the second chart has a point density of 50, but the color scale indicates 100.

Known workarounds

By setting the contour ranges for each plot individually and setting the ColorAxis to the same range, the combined plot is correct:

[
    Chart.PointDensity(
        x=(getZeroCollection 100),
        y=(getZeroCollection 100)
    ) 
    |> Chart.withColorAxisAnchor(1)
    |> GenericChart.mapiTrace (fun i t -> if i = 0 then t?contours <- (Contours.init(Start = 0, End = 100)); t else t)

    Chart.PointDensity(
        x = (getZeroCollection 50),
        y = (getZeroCollection 50)
    ) 
    |> Chart.withColorAxisAnchor(1)
    |> GenericChart.mapiTrace (fun i t -> if i = 0 then t?contours <- (Contours.init(Start = 0, End = 100)); t else t)
]
|> Chart.Grid(2,1)
|> Chart.withColorAxis(colorAxis=ColorAxis.init(CMin=0.,CMax=70.),Id=SubPlotId.ColorAxis 1)

image

Solution

  • The easiest solution is to add an option to either Chart.Grid or Chart.withLayoutStyle that enables to share the color axis for each density point chart.
  • If that is not possible, contours should be accessible from Chart.PointDensity()
@kMutagene
Copy link
Collaborator

Note that this is only relevant to the traces that pre-render the contours as an image layer, namely Contour and Histogram2DContour. I think these should expose min/max contour settings directly, in addition to exposing setting Contours as an object.

@kMutagene kMutagene added this to the Plotly.NET 5.0 milestone Oct 16, 2023
@kMutagene kMutagene added Area: MissingAbstraction Plotly.js functionality that has to be implemented Area: Core API labels Oct 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Core API Area: MissingAbstraction Plotly.js functionality that has to be implemented
Projects
None yet
Development

No branches or pull requests

2 participants