148
148
import traceback
149
149
import warnings
150
150
151
- from docutils .parsers .rst import directives
151
+ from docutils .parsers .rst import directives , Directive
152
152
from docutils .parsers .rst .directives .images import Image
153
- align = Image .align
154
153
import jinja2 # Sphinx dependency.
155
154
156
155
import matplotlib
165
164
else :
166
165
import matplotlib .pyplot as plt
167
166
from matplotlib import _pylab_helpers ,cbook
167
+ align = Image .align
168
168
169
169
__version__ = 2
170
170
174
174
# -----------------------------------------------------------------------------
175
175
176
176
177
+ @cbook .deprecated ("3.1" ,alternative = "PlotDirective" )
177
178
def plot_directive (name ,arguments ,options ,content ,lineno ,
178
179
content_offset ,block_text ,state ,state_machine ):
179
180
"""Implementation of the ``.. plot::`` directive.
@@ -241,25 +242,42 @@ def mark_plot_labels(app, document):
241
242
break
242
243
243
244
245
+ class PlotDirective (Directive ):
246
+ """Implementation of the ``.. plot::`` directive.
247
+
248
+ See the module docstring for details.
249
+ """
250
+
251
+ has_content = True
252
+ required_arguments = 0
253
+ optional_arguments = 2
254
+ final_argument_whitespace = False
255
+ option_spec = {
256
+ 'alt' :directives .unchanged ,
257
+ 'height' :directives .length_or_unitless ,
258
+ 'width' :directives .length_or_percentage_or_unitless ,
259
+ 'scale' :directives .nonnegative_int ,
260
+ 'align' :_option_align ,
261
+ 'class' :directives .class_option ,
262
+ 'include-source' :_option_boolean ,
263
+ 'format' :_option_format ,
264
+ 'context' :_option_context ,
265
+ 'nofigs' :directives .flag ,
266
+ 'encoding' :directives .encoding ,
267
+ }
268
+
269
+ def run (self ):
270
+ """Run the plot directive."""
271
+ return run (self .arguments ,self .content ,self .options ,
272
+ self .state_machine ,self .state ,self .lineno )
273
+
274
+
244
275
def setup (app ):
276
+ import matplotlib
245
277
setup .app = app
246
278
setup .config = app .config
247
279
setup .confdir = app .confdir
248
-
249
- options = {'alt' :directives .unchanged ,
250
- 'height' :directives .length_or_unitless ,
251
- 'width' :directives .length_or_percentage_or_unitless ,
252
- 'scale' :directives .nonnegative_int ,
253
- 'align' :_option_align ,
254
- 'class' :directives .class_option ,
255
- 'include-source' :_option_boolean ,
256
- 'format' :_option_format ,
257
- 'context' :_option_context ,
258
- 'nofigs' :directives .flag ,
259
- 'encoding' :directives .encoding
260
- }
261
-
262
- app .add_directive ('plot' ,plot_directive ,True , (0 ,2 ,False ),** options )
280
+ app .add_directive ('plot' ,PlotDirective )
263
281
app .add_config_value ('plot_pre_code' ,None ,True )
264
282
app .add_config_value ('plot_include_source' ,False ,True )
265
283
app .add_config_value ('plot_html_show_source_link' ,True ,True )
@@ -273,7 +291,8 @@ def setup(app):
273
291
274
292
app .connect ('doctree-read' ,mark_plot_labels )
275
293
276
- metadata = {'parallel_read_safe' :True ,'parallel_write_safe' :True }
294
+ metadata = {'parallel_read_safe' :True ,'parallel_write_safe' :True ,
295
+ 'version' :matplotlib .__version__ }
277
296
return metadata
278
297
279
298