plotly(figure)

The plotly function allows you to embed interactive Plotly charts into your application. It’s a powerful way to visualize data dynamically and intuitively.

Parameters

  • figure (Plotly figure object): The Plotly figure object to be rendered. This can be created using Plotly Express or the Plotly Graph Objects API.
  • size (float): (Optional) The width of the component in a row. Defaults to 1.0 (full row). See the Layout Guide for details.

Usage Example

Here’s a quick example demonstrating how to use the plotly function:

from preswald import plotly
import plotly.express as px

# Create a scatter plot using Plotly Express
fig = px.scatter(x=[1, 2, 3], y=[4, 5, 6], labels={"x": "X-axis", "y": "Y-axis"})

# Embed the Plotly chart into your app
plotly(fig)

Creating Plotly Charts

You can create a variety of charts using Plotly Express or Plotly Graph Objects, such as:

  • Line charts
  • Bar charts
  • Scatter plots
  • Pie charts
  • Histograms
  • 3D plots

Here’s an example of a bar chart:

from preswald import plotly
import plotly.express as px

# Data for the chart
data = {"Category": ["A", "B", "C"], "Values": [10, 20, 30]}
fig = px.bar(data, x="Category", y="Values", title="Sample Bar Chart")

# Embed the bar chart
plotly(fig)

Why Use plotly?

  • Interactivity: Zoom, pan, hover, and more.
  • Customization: Tailor every aspect of the chart to suit your needs.
  • Versatility: Supports a wide range of visualizations.

Visualize your data like never before with Plotly! 🌟