Skip to content

get_computed_values() with support for axis_ranges and axis_types (#5552)#5570

Open
Khanz9664 wants to merge 14 commits intoplotly:mainfrom
Khanz9664:main
Open

get_computed_values() with support for axis_ranges and axis_types (#5552)#5570
Khanz9664 wants to merge 14 commits intoplotly:mainfrom
Khanz9664:main

Conversation

@Khanz9664
Copy link
Copy Markdown

@Khanz9664 Khanz9664 commented Apr 12, 2026

Link to issue

#5552 - [FEATURE]: Access values calculated / derived by plotly.js as part of plotting

Closes #5552


Description of change

This PR introduces an initial implementation of get_computed_values() to expose values computed by Plotly.js in a structured and programmatic way.

The implementation supports retrieval of:

  • axis_ranges: The final computed [min, max] range for each axis
  • axis_types: The detected axis type (e.g., linear, log, date, category)

Key aspects of this implementation:

  • Provides a filtered interface over full_figure_for_development() to return only requested computed values
  • Uses a single-pass traversal of the layout to efficiently extract multiple computed properties
  • Uses a simple and robust startswith approach to identify axis keys (e.g., xaxis, yaxis, xaxis2)
  • Ensures JSON-serializable outputs by converting ranges to lists
  • Includes validation for the include parameter and early return for empty input

Demo

import plotly.graph_objects as go

# Create a sample figure
fig = go.Figure(go.Scatter(x=[1, 2, 3], y=[10, 20, 30]))

# Retrieve axis ranges
fig.get_computed_values(include=["axis_ranges"])
# {'axis_ranges': {'xaxis': [...], 'yaxis': [...]}}

# Retrieve axis types
fig.get_computed_values(include=["axis_types"])
# {'axis_types': {'xaxis': 'linear', 'yaxis': 'linear'}}

# Retrieve both together
fig.get_computed_values(include=["axis_ranges", "axis_types"])
# {
 #   'axis_ranges': {'xaxis': [...], 'yaxis': [...]},
#  'axis_types': {'xaxis': 'linear', 'yaxis': 'linear'}
# }

Testing strategy

Added a comprehensive test suite in tests/test_core/test_update_objects/test_get_computed_values.py:

  • Basic Extraction: Verified axis range extraction for standard plots
  • Multi-Axis Support: Verified handling of multiple axes (e.g., xaxis2, yaxis2)
  • Axis Types: Verified standalone extraction of axis types
  • Combined Retrieval: Verified correct behavior when requesting multiple keys together
  • Input Validation: Verified invalid inputs raise descriptive ValueError
  • Serialization Safety: Verified tuple ranges are converted to lists
  • Early Exit: Verified empty include skips rendering
  • Efficiency: Verified single call to full_figure_for_development() when multiple keys are requested

Note: Tests use mocking for the Kaleido rendering engine to ensure environment-agnostic reliability during CI.

Additional information (optional)

This implementation establishes the API structure for accessing computed Plotly.js values and demonstrates its extensibility by supporting multiple properties (axis_ranges, axis_types) using a scalable single-pass design.

Future extensions could include:

  • tick values and tick labels
  • margins and layout-derived geometry
  • box/violin plot statistics
  • direct integration with FigureWidget to avoid reliance on Kaleido

Guidelines

@Khanz9664 Khanz9664 changed the title get_computed_values() method to access computed axis ranges (#5552) Add get_computed_values() with support for axis_ranges and axis_types (#5552) Apr 15, 2026
@Khanz9664
Copy link
Copy Markdown
Author

Hi! This is my first contribution to the project.

I noticed that the workflow is awaiting approval to run.
Could a maintainer please review and approve the workflows so CI checks can proceed?

Thank you!

@Khanz9664 Khanz9664 changed the title Add get_computed_values() with support for axis_ranges and axis_types (#5552) get_computed_values() with support for axis_ranges and axis_types (#5552) Apr 15, 2026
@emilykl
Copy link
Copy Markdown
Contributor

emilykl commented Apr 15, 2026

@Khanz9664 Done! Sorry for the inconvenience, we are migrating our CI pipelines at the moment and some settings may change for the next few weeks. You should be good to go for this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE]: Access values calculated / derived by plotly.js as part of plotting

2 participants