[Bug]: matplotlib.sphinxext.plot_directive: Changing DPI value in `plot_formats` leads to unexpected figure sizes
維護者通常 1 天內回覆
還沒有人認領這個 Issue。
評估
- 難度
- 3/5
- 預估耗時
- 1-2 天
- 新手友好度
- 58/100
- Issue 類型
- 缺陷
- 描述清晰度
- 基本清楚
- 活躍度
- 活躍
- 技術堆疊
- matplotlib, python
研究方向
Start by reading matplotlib.sphinxext.plot_directive and trace how plot_formats DPI is applied when saving figures, especially for plots with and without a directive width. Reproduce the two examples in a Sphinx build using plot_formats = ['png'] and [('png', 200)]; done means changing DPI preserves the first figure's physical size while producing the expected higher pixel resolution.
由索引模型根據 Issue 內容生成。
描述
When using the plot:: directive in Sphinx (i.e., using matplotlib.sphinxext.plot_directive): Modifying the resolution via the configuration variable plot_formats in Sphinx's conf.py leads to unexpected sizes of the resulting figures:
Setting plot_formats = ['png'] produces:
The first image is made up 160x160 pixels and the second image is made up of 320x320 pixel.
Setting plot_formats = plot_formats = [('png', 200)] produces:
The first image is made up 400x400 pixels and the second image is made up of 800x800 pixel.
I expected that just the resolution and not the size of the first figure would change (analogous to the second figure).
The ReST source:
*************************
SphinxPlots documentation
*************************
A default matplotlib plot followed by a two inch wide SVG image:
.. plot::
import matplotlib.pyplot as plt
fig, ax = plt.subplots(facecolor='gray', figsize=(2, 2))
fig.suptitle(f"Size: {fig.get_size_inches()} in")
ax.plot([0, 1, 2, 3], [0, 1, -2, .5])
plt.show()
.. image:: _static/2inBox.svg
:alt: SphinxPlots logo
:align: center
:width: 2in
A 4 inch wide plot, which is parametrized by Sphinx to width of two inch width:
.. plot::
:width: 2in
import matplotlib.pyplot as plt
fig, ax = plt.subplots(facecolor='gray', figsize=(4, 4))
fig.suptitle(f"Size: {fig.get_size_inches()} in")
ax.plot([0, 1, 2, 3], [0, 1, -2, .5])
plt.show()
.. image:: _static/2inBox.svg
:alt: SphinxPlots logo
:align: center
:width: 2in
Sphinx's configurtion conf.py:
extensions = [
'matplotlib.sphinxext.plot_directive',
'matplotlib.sphinxext.figmpl_directive',
]
templates_path = ['_templates']
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
# -- Options for HTML output -------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
html_theme = 'alabaster'
html_static_path = ['_static']
plot_include_source = False
plot_html_show_formats = True
plot_html_show_source_link = False
# plot_srcset = ['4x']
plot_formats = ['png'] # first case
# plot_formats = [('png', 200)] # second case
Doing plot_formats = [('webp', 200)] leads to comparable results.
- 主要語言
- Python
- 星號
- 23.6k
- 分支
- 8.6k
- 平均合併
- 1 天 19 小時
- 30 天內合併 PR
- 64
環境準備
在瀏覽器裡用你自己的 GitHub 帳號啟動這個專案的開發容器。
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
matplotlib/matplotlib 的其他 Issue
-
[Bug]: Saving a NonUniformImage with bbox_inches="tight" raises TypeError when extent is omitted可能已有人在做 關聯的 PR 仍在進行中或已合併。 未關閉
難度 2/5 1-3 小時 新手友好度 74/100
matplotlib/matplotlib#32707 ·
維護者通常 1 天內回覆
-
[Bug]: withTickedStroke raises ValueError when the line contains NaN可能已有人在做 @RjyavardhanSingh 於 4 天前認領。 未關閉first-contribution topic: path handling
難度 2/5 1-3 小時 新手友好度 85/100
matplotlib/matplotlib#32689 · 2 則留言 ·
維護者通常 1 天內回覆
-
[Bug]: Constrained layout raises ZeroDivisionError when the first height/width ratio is zero可能已有人在做 @yqtian-se 於 1 天前認領。 未關閉
難度 2/5 1-3 小時 新手友好度 85/100
matplotlib/matplotlib#32684 · 3 則留言 ·
維護者通常 1 天內回覆
-
[Bug]: twin axes ignore the navigation opt-outs可能已有人在做 @NaumanRafay 於 37 天前認領。 未關閉topic: toolbar
難度 2/5 1-3 小時 新手友好度 78/100
matplotlib/matplotlib#32528 · 2 則留言 ·
維護者通常 1 天內回覆
-
[Bug]: macOS font discovery raises KeyError('_items') for an incomplete system_profiler font record未關閉first-contribution OS: Apple status: needs clarification topic: text/fonts
難度 2/5 1-3 小時 新手友好度 84/100
matplotlib/matplotlib#32328 · 4 則留言 ·
維護者通常 1 天內回覆
查看 matplotlib/matplotlib 的全部 Issue
相似的 Issue
-
難度 2/5 1-3 小時 新手友好度 72/100
plone/plone.observability#114 ·
維護者通常 1 天內回覆
-
area:docs type:docs
難度 2/5 1-3 小時 新手友好度 68/100
jejjohnson/gauss_flows#246 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 78/100
維護者通常 1 天內回覆
-
netbox status: needs triage type: feature
難度 2/5 1-3 小時 新手友好度 68/100
netbox-community/netbox#23868 ·
維護者通常 2 天內回覆
-
難度 2/5 1-3 小時 新手友好度 65/100
emeryberger/CSrankings#15757 ·
維護者通常 9 天內回覆