.Figure()
Published Oct 2, 2024
Contribute to Docs
The .Figure()
class in Plotly is used to create and manipulate figures. It provides a high-level interface for creating complex visualizations.
Syntax
plotly.graph_objects.Figure(data=None, layout=None, frames=None, skip_invalid=False, **kwargs)
data
: List of trace objects defining the visual data (e.g., go.Scatter).layout
: Layout object or dictionary for customizing figure appearance (e.g., titles, axes).frames
: List of frame objects used for creating animations within the figure.skip_invalid
: Boolean to skip invalid properties without raising errors.**kwargs
: Additional keyword arguments for further customization of the figure.
Example
The following example showcases the use of .Figure()
:
import plotly.graph_objects as goyears = [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 line graph representing global inflation rates over the past five years. It defines data
for the plot, layout
for appearance settings, and frames
for animation steps before passing them to the Figure()
class to generate the visualization.
The above code generates the following code
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn Python:Plotly on Codecademy
- Career path
Computer Science
Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!Includes 6 CoursesWith Professional CertificationBeginner Friendly75 hours - Course
Learn Python 3
Learn the basics of Python 3.12, one of the most powerful, versatile, and in-demand programming languages today.With CertificateBeginner Friendly23 hours