@@ -28,6 +28,7 @@ def get_tikz_code(
28
28
tex_relative_path_to_data = None ,
29
29
strict = False ,
30
30
wrap = True ,
31
+ axis_environment = True ,
31
32
extra_axis_parameters = None ,
32
33
extra_tikzpicture_parameters = None ,
33
34
dpi = None ,
@@ -84,6 +85,12 @@ def get_tikz_code(
84
85
Default is ``True``.
85
86
:type wrap: bool
86
87
88
+ :param axis_environment: Whether ``'\\ begin{axis}[...]'`` and
89
+ ``'\\ end{axis}'`` will be written. One needs to
90
+ set the environment in the document. If ``False``
91
+ additionally sets ``wrap=False``.
92
+ :type axis_environment: bool
93
+
87
94
:param extra_axis_parameters: Extra axis options to be passed (as a set)
88
95
to pgfplots. Default is ``None``.
89
96
:type extra_axis_parameters: a set of strings for the pfgplots axes.
@@ -126,6 +133,8 @@ def get_tikz_code(
126
133
data ['custom colors' ] = {}
127
134
data ['legend colors' ] = []
128
135
data ['extra tikzpicture parameters' ] = extra_tikzpicture_parameters
136
+ data ['axis environment' ] = axis_environment
137
+ data ['show_info' ] = show_info
129
138
# rectangle_legends is used to keep track of which rectangles have already
130
139
# had \addlegendimage added. There should be only one \addlegenimage per
131
140
# bar chart data series.
@@ -143,6 +152,10 @@ def get_tikz_code(
143
152
savefig_dpi if isinstance (savefig_dpi , int ) \
144
153
else mpl .rcParams ['figure.dpi' ]
145
154
155
+ # print message about necessary pgfplot libs to command line
156
+ if show_info :
157
+ _print_pgfplot_libs_message (data )
158
+
146
159
# gather the file content
147
160
data , content = _recurse (data , figure )
148
161
@@ -158,7 +171,7 @@ def get_tikz_code(
158
171
code += _tex_comment (disclaimer )
159
172
160
173
# write the contents
161
- if wrap :
174
+ if wrap and axis_environment :
162
175
code += '\\ begin{tikzpicture}\n \n '
163
176
if extra_tikzpicture_parameters :
164
177
code += ',\n ' .join (data ['extra tikzpicture parameters' ])
@@ -171,12 +184,9 @@ def get_tikz_code(
171
184
172
185
code += '' .join (content )
173
186
174
- if wrap :
187
+ if wrap and axis_environment :
175
188
code += '\\ end{tikzpicture}'
176
189
177
- # print message about necessary pgfplot libs to command line
178
- if show_info :
179
- _print_pgfplot_libs_message (data )
180
190
return code
181
191
182
192
@@ -275,11 +285,20 @@ def _recurse(data, obj):
275
285
# add extra axis options from children
276
286
if data ['extra axis options' ]:
277
287
ax .axis_options .extend (data ['extra axis options' ])
278
- # populate content
279
- content .extend (
280
- ax .get_begin_code () +
281
- children_content +
282
- [ax .get_end_code (data )], 0 )
288
+ # populate content and add axis environment if wished
289
+ if data ['axis environment' ]:
290
+ content .extend (
291
+ ax .get_begin_code () +
292
+ children_content +
293
+ [ax .get_end_code (data )], 0 )
294
+ else :
295
+ content .extend (children_content , 0 )
296
+ # print axis environment options, if told to show infos
297
+ if data ['show_info' ]:
298
+ print ("=========================================================" )
299
+ print ("These would have been the properties of the environment:" )
300
+ print ('' .join (ax .get_begin_code ()[1 :]))
301
+ print ("=========================================================" )
283
302
elif isinstance (child , mpl .lines .Line2D ):
284
303
data , cont = line2d .draw_line2d (data , child )
285
304
content .extend (cont , child .get_zorder ())
0 commit comments