Skip to content

Commit 6bd9dde

Browse files
authored
Add iframe-width and height options (#19)
1 parent 877f4fd commit 6bd9dde

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

docs/source/examples.rst

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,25 @@ By default, the following code will be executed before running each code block.
7272
title = "plotly version: {}".format(plotly.__version__)
7373
fig1 = go.Figure(go.Scatter(x=x, y=y), layout=dict(title=title))
7474
fig2 = px.scatter(x=x, y=y, title=title)
75+
76+
77+
Specify figure size
78+
~~~~~~~~~~~~~~~~~~~
79+
80+
.. plotly::
81+
:iframe-width: 500px
82+
:iframe-height: 300px
83+
84+
import plotly.express as px
85+
86+
px.scatter(x=[0, 1, 2, 3, 4], y=[0, 1, 4, 9, 16])
87+
88+
89+
You can set the default ``iframe-width`` and ``iframe-height`` by specifying ``plotly_iframe_width`` (default: ``"100%"``) and ``plotly_iframe_height`` (default: ``"500px"``) in ``conf.py``.
90+
91+
.. code-block:: python
92+
93+
# conf.py
94+
95+
plotly_iframe_width = "500px"
96+
plotly_iframe_height = "300px"

sphinx_plotly_directive/__init__.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,8 @@ class PlotlyDirective(Directive):
256256
"encoding": directives.encoding,
257257
"caption": directives.unchanged,
258258
"fig-vars": _option_fig_vars,
259+
"iframe-width": directives.unchanged,
260+
"iframe-height": directives.unchanged,
259261
}
260262

261263
def run(self):
@@ -680,6 +682,8 @@ def run(arguments, content, options, state_machine, state, lineno):
680682
options_copy = copy.deepcopy(options)
681683

682684
options.setdefault("include-source", config.plotly_include_source)
685+
options.setdefault("iframe-width", config.plotly_iframe_width)
686+
options.setdefault("iframe-height", config.plotly_iframe_height)
683687
keep_context = "context" in options
684688
context_opt = None if not keep_context else options["context"]
685689

@@ -853,8 +857,8 @@ def run(arguments, content, options, state_machine, state, lineno):
853857
multi_figure=len(figures) > 1,
854858
options=opts,
855859
figures=figures,
856-
iframe_width=config.plotly_iframe_width,
857-
iframe_height=config.plotly_iframe_height,
860+
iframe_width=options["iframe-width"],
861+
iframe_height=options["iframe-height"],
858862
source_code=source_code,
859863
html_show_formats=config.plotly_html_show_formats and len(figures),
860864
caption=caption,

0 commit comments

Comments
 (0)