Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

DOC: plot-directive warning filter option#27076

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes fromall 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
38 changes: 27 additions & 11 deletionslib/matplotlib/sphinxext/plot_directive.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -78,6 +78,12 @@
figure. This overwrites the caption given in the content, when the plot
is generated from a file.

``:filter-warning:`` : str
When specified, will ignore warnings that match the input string, which is
a warnings filter `message regex <msg>`_ string.

.. _msg: https://docs.python.org/3/library/warnings.html#the-warnings-filter

Additionally, this directive supports all the options of the `image directive
<https://docutils.sourceforge.io/docs/ref/rst/directives.html#image>`_,
except for ``:target:`` (since plot will add its own target). These include
Expand DownExpand Up@@ -177,6 +183,7 @@
import sys
import textwrap
import traceback
import warnings

from docutils.parsers.rst import directives, Directive
from docutils.parsers.rst.directives.images import Image
Expand DownExpand Up@@ -221,6 +228,10 @@ def _option_format(arg):
return directives.choice(arg, ('python', 'doctest'))


def _option_string(arg):
return arg if arg.strip() else False


def mark_plot_labels(app, document):
"""
To make plots referenceable, we need to move the reference from the
Expand DownExpand Up@@ -271,7 +282,8 @@ class PlotDirective(Directive):
'context': _option_context,
'nofigs': directives.flag,
'caption': directives.unchanged,
}
'filter-warning': _option_string,
}

def run(self):
"""Run the plot directive."""
Expand DownExpand Up@@ -854,16 +866,20 @@ def run(arguments, content, options, state_machine, state, lineno):

# make figures
try:
results = render_figures(code=code,
code_path=source_file_name,
output_dir=build_dir,
output_base=output_base,
context=keep_context,
function_name=function_name,
config=config,
context_reset=context_opt == 'reset',
close_figs=context_opt == 'close-figs',
code_includes=source_file_includes)
with warnings.catch_warnings(record=True) as w:
if msg := options.get('filter-warning', False):
warnings.filterwarnings('ignore', message=msg)

results = render_figures(code=code,
code_path=source_file_name,
output_dir=build_dir,
output_base=output_base,
context=keep_context,
function_name=function_name,
config=config,
context_reset=context_opt == 'reset',
close_figs=context_opt == 'close-figs',
code_includes=source_file_includes)
errors = []
except PlotError as err:
reporter = state.memo.reporter
Expand Down
8 changes: 8 additions & 0 deletionslib/matplotlib/tests/tinypages/some_plots.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -174,3 +174,11 @@ Plot 21 is generated via an include directive:
Plot 22 uses a different specific function in a file with plot commands:

.. plot:: range6.py range10

Plot 23 filters a missing glyph warning

.. plot::
:filter-warning: Glyph

plt.text(.5, .5, "Hello 🙃 World!")


[8]ページ先頭

©2009-2025 Movatter.jp