Skip to content

Enable Update of Plot Axis Range from Button #414

Closed

Description

@mg-yolo-enterprises

It would be helpful to be able to use an UpdateMenu to permit a user to change the range of a plot's axis.

This seems possible, based on example code for Plotly for Python:
https://community.plotly.com/t/pre-defined-range-buttons/39267/3

However I don't see how it's possible to do this from Plotly.NET, based on the need to send an axis start and end value.

I've attempted this with the following code, and several variations:

var buttons = new List<UpdateMenuButton>();
for (var time = timeInterval.StartInterval; time < timeInterval.EndInterval; time = time.AddHours(1))
{
    buttons.Add(UpdateMenuButton.init(
        Label: $"{time:h:mm tt}", 
        Method: StyleParam.UpdateMethod.Relayout,
        Args: new[] { "xaxis.range", 
            $"{time:yyyy-MM-dd HH:mm:ss} - {time.AddHours(1):yyyy-MM-dd HH:mm:ss}" }
        ));
}

and

.WithLayout(layout: Layout.init<iConv>(UpdateMenus: new []{UpdateMenu.init(Buttons: buttons)}))

Using the above code, the UpdateMenu appears, the labels are correct, and selecting something does change the X axis range. However, it always changes to 1/1/2000 - 12/31/2000 rather than the desired range.

Activity

  1. kMutagene commented on Sep 4, 2023

    @kMutagene
    Collaborator

    Hi @mg-yolo-enterprises, thanks for reporting this.

    I played around a little and it seems like IEnumerable<string> is just not enough for modelling Args, as the correct json for your example is

    "buttons": [
     {
      "args": [
       "xaxis.range",
       [
        "2015-07-01",
        "2015-09-01"
       ]
      ],
      "label": "Custom",
      "method": "relayout"
     }
    ]

    note that the range argument is a real json array with two values, something you cannot put there with just a string.

    So we need to allow any type of object in the Args array to solve this.

  2. added this to the Plotly.NET 5.0 milestone on Sep 4, 2023
  3. added a commit that references this issue on Apr 2, 2024
    f107eba
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

      Issue actions