Skip to content
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

[Term Entry] Python Plotly- graph_objects .Figure() #5199

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions content/plotly/concepts/graph-objects/terms/figure/figure.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
---
Title: 'graph_objects.Figure()'
Description: 'Creates and manipulates figures in Plotly.'
Subjects:
- 'Data Science'
- 'Data Visualization'
Tags:
- 'Plotly'
- 'Graphs'
- 'Data'
- 'Visualization'
CatalogContent:
- 'learn-python-3'
- 'paths/computer-science'
---

The **`graph_objects.Figure()`** class in Plotly is used to create and manipulate figures. It provides a high-level interface for creating complex visualizations.

## Syntax

```pseudo
plotly.graph_objects.Figure(data=None, layout=None, frames=None)
```

- `data`: A list or tuple of trace instances (e.g., [Scatter(...), Bar(...)]).
- `layout`: An instance of plotly.graph_objects.Layout or a dictionary of layout properties.
- `frames`: A list of frames, each frame being a dictionary of properties.

## Example

The following example showcases the use of the `.Figure()` function:

```py
import plotly.graph_objects as go

years = [2019, 2020, 2021, 2022, 2023]
inflation_rates = [2.21, 1.94, 3.47, 7.97, 5.41]

data = [go.Scatter(x=years, y=inflation_rates, mode='lines+markers', name='Inflation Rate')]

layout = go.Layout(
title='Global Inflation Over the Last 5 Years',
xaxis_title='Year',
yaxis_title='Inflation Rate (%)',
template='plotly_dark'
)

frames = [go.Frame(data=[go.Scatter(x=years[:k+1], y=inflation_rates[:k+1])]) for k in range(len(years))]

fig = go.Figure(data=data, layout=layout, frames=frames)

fig.show()
```

This example creates a graph representing the inflation for the last five years, creating the values for data, layout and frames before given them to `Figure()`.

The above code generates the following code

![Example for Figure() on Plotly output](plotly_figure_example.png)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.