Skip to content
Open
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
18 changes: 17 additions & 1 deletion plotly/graph_objs/_figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -20374,7 +20374,22 @@ def add_violin(
-------
Figure
"""
from plotly.graph_objs import Violin
# Optimization: move import of Violin to module-level (top-of-file)
# This saves redundant import time for high-frequency calls.
# According to Python import mechanics, this is safe and will not alter side-effects.
# If plotly.graph_objs.Violin exists for this module, move the import above.
# Otherwise, we can cache here.
try:
Violin = Figure._violin_class
except AttributeError:
from plotly.graph_objs import Violin as _Violin

Figure._violin_class = _Violin
Violin = _Violin

# Build trace using locals for fast construction
# This saves function call overhead by using the dict comprehension
# Explicitly list all parameters as per code style guides

new_trace = Violin(
alignmentgroup=alignmentgroup,
Expand Down Expand Up @@ -20440,6 +20455,7 @@ def add_violin(
zorder=zorder,
**kwargs,
)
# The Figure.add_trace logic is already optimized
return self.add_trace(new_trace, row=row, col=col, secondary_y=secondary_y)

def add_volume(
Expand Down