Skip to content

Contours should be accessible for PointDensity charts #426

Closed
@bvenn

Description

@bvenn
Collaborator

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()

Activity

kMutagene

kMutagene commented on Oct 12, 2023

@kMutagene
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.

added this to the Plotly.NET 5.0 milestone on Oct 16, 2023
added a commit that references this issue on Apr 2, 2024
fe740ec
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @kMutagene@bvenn

        Issue actions

          Contours should be accessible for PointDensity charts · Issue #426 · plotly/Plotly.NET