[ENH] Add option to render multiple images from same cell as single-img#1384
[ENH] Add option to render multiple images from same cell as single-img#1384larsoner merged 14 commits intosphinx-gallery:masterfrom
Conversation
b36efc9 to
0cc1264
Compare
sphinx_gallery/scrapers.py
Outdated
| # Determine whether single-img should be converted to multi-img | ||
| convert_to_multi_image = True # default is to convert | ||
| if block_vars.get("multi_image") is not None: # block setting takes precedence | ||
| convert_to_multi_image = block_vars["multi_image"] != "single" | ||
| elif block_vars["file_conf"].get("multi_image") is not None: # then file setting | ||
| convert_to_multi_image = block_vars["file_conf"]["multi_image"] != "single" |
There was a problem hiding this comment.
This in the scraper prioritises checking the block-specific setting, then falls back to the file-wide setting.
|
Will address the failing tests and start to think about new unit tests for these features tomorrow. |
| This example demonstrates how to import a local module and how images are stacked when | ||
| two plots are created in one code block (see the :doc:`plot_9_multi_image_separate` | ||
| example for information on controlling this behaviour). The variable ``N`` from the |
There was a problem hiding this comment.
Noticed that the plot exp example discussed images being stacked side-by-side, so added a link to the new example mentioning this behaviour can be changed.
| Force plots to be displayed on separate lines | ||
| ============================================= | ||
| This example demonstrates how the visualisation of multiple plots produced from a single | ||
| code block can be controlled. The default behaviour is to stack plots side-by-side, | ||
| however this can be overridden to display each plot created by the code block on a | ||
| separate line, preserving their size. |
There was a problem hiding this comment.
Added a new example demonstrating the sphinx_gallery_multi_image and ..._block options.
| # Add `sphinx_gallery_multi_image_block` setting to block variables | ||
| # (extract config rather than just regex search since the option's value is needed) | ||
| script_vars["multi_image"] = py_source_parser.extract_file_config( | ||
| block.content | ||
| ).get("multi_image_block") |
There was a problem hiding this comment.
Would be interested if others think there's a better way to handle this.
Of course just a regex search is possible, but unlike the defer_figures flag we need to extract the value of variable, which the extract_file_config() func can handle.
|
Have added entries for the new config options in the docs. Also added to the unit tests, however they start from the point where |
It looks like you added to |
Okay, I added to |
|
Thanks @tsbinns ! |
Discussed in #1371.
3 ideas were proposed:
max-widthformulti-img# sphinx_gallery_multi_image = singlesomewhere in the file# sphinx_gallery_multi_image_block = singlewithin that blockThis PR so far addresses point 2 (adding a config setting for the whole example). Will have a go at point 3 as well.