Skip to content

Log warning during ..plot to sphix logger#30931

Open
Daniel53245 wants to merge 2 commits into
matplotlib:mainfrom
Daniel53245:log-plot-warning-with-sphinx
Open

Log warning during ..plot to sphix logger#30931
Daniel53245 wants to merge 2 commits into
matplotlib:mainfrom
Daniel53245:log-plot-warning-with-sphinx

Conversation

@Daniel53245

@Daniel53245 Daniel53245 commented Jan 4, 2026

Copy link
Copy Markdown

PR summary

closes #15715

As described in #15715, currently the warning in the ..plot is not correctly handled by the sphinx
By modifying file lib/matplotlib/sphinxext/plot_directive.py , I catch any warning generated during the code execution and log it through sphinx logs. When compiling the document, sphinx will fail on warning with the -W flag

(matplotlib_dev_env) PS D:\CodeProjects\matplot_lib_test_file> sphinx-build -E  -b html -d _build/doctrees   . _build/html -W    
Running Sphinx v9.1.0
loading translations [en]... done
building [mo]: targets for 0 po files that are out of date
writing output... 
building [html]: targets for 1 source files that are out of date
updating environment: [new config] 1 added, 0 changed, 0 removed
reading sources... [100%] index
WARNING: [plot] Python warning during plot execution: A warning occurred (UserWarning)
looking for now-outdated files... none found
pickling environment... done
checking consistency... done
preparing documents... done
copying assets... 
copying downloadable files... [100%] _build/plot_directive/index-1.py
copying static files... 
Writing evaluated template result to D:\CodeProjects\matplot_lib_test_file\_build\html\_static\basic.css
Writing evaluated template result to D:\CodeProjects\matplot_lib_test_file\_build\html\_static\documentation_options.js
Writing evaluated template result to D:\CodeProjects\matplot_lib_test_file\_build\html\_static\language_data.js
Writing evaluated template result to D:\CodeProjects\matplot_lib_test_file\_build\html\_static\alabaster.css
copying static files: done
copying extra files... 
copying extra files: done
copying assets: done
writing output... [100%] index
generating indices... genindex done
writing additional pages... search done
dumping search index in English (code: en)... done
dumping object inventory... done
build finished with problems, 1 warning (with warnings treated as errors).
(matplotlib_dev_env) PS D:\CodeProjects\matplot_lib_test_file> 

PR checklist

@Daniel53245
Daniel53245 marked this pull request as draft January 4, 2026 07:52
@Daniel53245
Daniel53245 marked this pull request as ready for review January 5, 2026 02:21
@tacaswell
tacaswell force-pushed the log-plot-warning-with-sphinx branch from 9296ac3 to bf7a2de Compare July 18, 2026 03:31
@tacaswell

Copy link
Copy Markdown
Member

I have rebased this and manually tested that it works.

The next step is to copy the test added in https://github.com/matplotlib/matplotlib/pull/31863/changes to also exercise this failure mode.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Warnings in plot directive aren't treated as such by Sphinx

3 participants