Skip to content

Commit e0dd986

Browse files
authored
Merge pull request #377 from nschloe/figurewidth-axiswidth
rename figure{width,height} to axis_{width,height}
2 parents 266c20e + e852afb commit e0dd986

File tree

3 files changed

+63
-69
lines changed

3 files changed

+63
-69
lines changed

test/test_rotated_labels.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def test_rotated_labels_parameters(
5959
if y_tick_label_width:
6060
extra_dict["y tick label text width"] = y_tick_label_width
6161

62-
tikzplotlib.save(tikz_file, figurewidth="7.5cm", extra_axis_parameters=extra_dict)
62+
tikzplotlib.save(tikz_file, axis_width="7.5cm", extra_axis_parameters=extra_dict)
6363

6464
# close figure
6565
plt.close(fig)
@@ -94,7 +94,7 @@ def test_rotated_labels_parameters_different_values(
9494
if y_tick_label_width:
9595
extra_dict["y tick label text width"] = y_tick_label_width
9696

97-
tikzplotlib.save(tikz_file, figurewidth="7.5cm", extra_axis_parameters=extra_dict)
97+
tikzplotlib.save(tikz_file, axis_width="7.5cm", extra_axis_parameters=extra_dict)
9898

9999
# close figure
100100
plt.close(fig)
@@ -116,7 +116,7 @@ def test_rotated_labels_parameters_no_ticks():
116116
_, tmp_base = tempfile.mkstemp()
117117
tikz_file = tmp_base + "_tikz.tex"
118118

119-
tikzplotlib.save(tikz_file, figurewidth="7.5cm")
119+
tikzplotlib.save(tikz_file, axis_width="7.5cm")
120120

121121
# close figure
122122
plt.close(fig)

tikzplotlib/_axes.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -166,34 +166,34 @@ def get_end_code(self, data):
166166
return ""
167167

168168
def _set_axis_dimensions(self, data, aspect_num, xlim, ylim):
169-
if data["fwidth"] and data["fheight"]:
169+
if data["axis width"] and data["axis height"]:
170170
# width and height overwrite aspect ratio
171-
self.axis_options.append("width=" + data["fwidth"])
172-
self.axis_options.append("height=" + data["fheight"])
173-
elif data["fwidth"]:
174-
# only data['fwidth'] given. calculate height by the aspect ratio
175-
self.axis_options.append("width=" + data["fwidth"])
171+
self.axis_options.append("width=" + data["axis width"])
172+
self.axis_options.append("height=" + data["axis height"])
173+
elif data["axis width"]:
174+
# only data["axis width"] given. calculate height by the aspect ratio
175+
self.axis_options.append("width=" + data["axis width"])
176176
if aspect_num:
177177
alpha = aspect_num * (ylim[1] - ylim[0]) / (xlim[1] - xlim[0])
178178
if alpha == 1.0:
179-
data["fheight"] = data["fwidth"]
179+
data["axis height"] = data["axis width"]
180180
else:
181-
# Concatenate the literals, as data['fwidth'] could as well
181+
# Concatenate the literals, as data["axis width"] could as well
182182
# be a LaTeX length variable such as \figurewidth.
183-
data["fheight"] = str(alpha) + "*" + data["fwidth"]
184-
self.axis_options.append("height=" + data["fheight"])
185-
elif data["fheight"]:
186-
# only data['fheight'] given. calculate width by the aspect ratio
187-
self.axis_options.append("height=" + data["fheight"])
183+
data["axis height"] = str(alpha) + "*" + data["axis width"]
184+
self.axis_options.append("height=" + data["axis height"])
185+
elif data["axis height"]:
186+
# only data["axis height"] given. calculate width by the aspect ratio
187+
self.axis_options.append("height=" + data["axis height"])
188188
if aspect_num:
189189
alpha = aspect_num * (ylim[1] - ylim[0]) / (xlim[1] - xlim[0])
190190
if alpha == 1.0:
191-
data["fwidth"] = data["fheight"]
191+
data["axis width"] = data["axis height"]
192192
else:
193-
# Concatenate the literals, as data['fheight'] could as
193+
# Concatenate the literals, as data["axis height"] could as
194194
# well be a LaTeX length variable such as \figureheight.
195-
data["fwidth"] = str(1.0 / alpha) + "*" + data["fheight"]
196-
self.axis_options.append("width=" + data["fwidth"])
195+
data["axis width"] = str(1.0 / alpha) + "*" + data["axis height"]
196+
self.axis_options.append("width=" + data["axis width"])
197197
else:
198198
# TODO keep an eye on https://tex.stackexchange.com/q/480058/13262
199199
pass

tikzplotlib/_save.py

Lines changed: 43 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
def get_tikz_code(
1818
figure="gcf",
1919
filepath=None,
20-
figurewidth=None,
21-
figureheight=None,
20+
axis_width=None,
21+
axis_height=None,
2222
textsize=10.0,
2323
tex_relative_path_to_data=None,
2424
externalize_tables=False,
@@ -41,63 +41,57 @@ def get_tikz_code(
4141
4242
:param figure: either a Figure object or 'gcf' (default).
4343
44-
:param figurewidth: If not ``None``, this will be used as figure width
45-
within the TikZ/PGFPlots output. If ``figureheight``
46-
is not given, ``tikzplotlib`` will try to preserve
47-
the original width/height ratio.
48-
Note that ``figurewidth`` can be a string literal,
49-
such as ``'\\figurewidth'``.
50-
:type figurewidth: str
51-
52-
:param figureheight: If not ``None``, this will be used as figure height
53-
within the TikZ/PGFPlots output. If ``figurewidth`` is
54-
not given, ``tikzplotlib`` will try to preserve
55-
the original width/height ratio. Note that
56-
``figurewidth`` can be a string literal, such as
57-
``'\\figureheight'``.
58-
:type figureheight: str
59-
60-
:param textsize: The text size (in pt) that the target latex document is
61-
using. Default is 10.0.
44+
:param axis_width: If not ``None``, this will be used as figure width within the
45+
TikZ/PGFPlots output. If ``axis_height`` is not given,
46+
``tikzplotlib`` will try to preserve the original width/height
47+
ratio. Note that ``axis_width`` can be a string literal, such as
48+
``'\\axis_width'``.
49+
:type axis_width: str
50+
51+
:param axis_height: If not ``None``, this will be used as figure height within the
52+
TikZ/PGFPlots output. If ``axis_width`` is not given,
53+
``tikzplotlib`` will try to preserve the original width/height
54+
ratio. Note that ``axis_width`` can be a string literal, such
55+
as ``'\\axis_height'``.
56+
:type axis_height: str
57+
58+
:param textsize: The text size (in pt) that the target latex document is using.
59+
Default is 10.0.
6260
:type textsize: float
6361
64-
:param tex_relative_path_to_data: In some cases, the TikZ file will have to
65-
refer to another file, e.g., a PNG for
66-
image plots. When ``\\input`` into a
67-
regular LaTeX document, the additional
68-
file is looked for in a folder relative
69-
to the LaTeX file, not the TikZ file.
70-
This arguments optionally sets the
71-
relative path from the LaTeX file to the
72-
data.
62+
:param tex_relative_path_to_data: In some cases, the TikZ file will have to refer to
63+
another file, e.g., a PNG for image plots. When
64+
``\\input`` into a regular LaTeX document, the
65+
additional file is looked for in a folder relative
66+
to the LaTeX file, not the TikZ file. This
67+
arguments optionally sets the relative path from
68+
the LaTeX file to the data.
7369
:type tex_relative_path_to_data: str
7470
75-
:param externalize_tables: Whether or not to externalize plot data tables
76-
into tsv files.
71+
:param externalize_tables: Whether or not to externalize plot data tables into tsv
72+
files.
7773
:type externalize_tables: bool
7874
79-
:param override_externals: Whether or not to override existing external
80-
files (such as tsv or images) with conflicting
81-
names (the alternative is to choose other
82-
names).
75+
:param override_externals: Whether or not to override existing external files (such
76+
as tsv or images) with conflicting names (the alternative
77+
is to choose other names).
8378
:type override_externals: bool
8479
85-
:param strict: Whether or not to strictly stick to matplotlib's appearance.
86-
This influences, for example, whether tick marks are set
87-
exactly as in the matplotlib plot, or if TikZ/PGFPlots
88-
can decide where to put the ticks.
80+
:param strict: Whether or not to strictly stick to matplotlib's appearance. This
81+
influences, for example, whether tick marks are set exactly as in the
82+
matplotlib plot, or if TikZ/PGFPlots can decide where to put the
83+
ticks.
8984
:type strict: bool
9085
91-
:param wrap: Whether ``'\\begin{tikzpicture}'`` and
92-
``'\\end{tikzpicture}'`` will be written. One might need to
93-
provide custom arguments to the environment (eg. scale= etc.).
94-
Default is ``True``.
86+
:param wrap: Whether ``'\\begin{tikzpicture}'`` and ``'\\end{tikzpicture}'`` will be
87+
written. One might need to provide custom arguments to the environment
88+
(eg. scale= etc.). Default is ``True``.
9589
:type wrap: bool
9690
97-
:param add_axis_environment: Whether ``'\\begin{axis}[...]'`` and
98-
``'\\end{axis}'`` will be written. One needs to
99-
set the environment in the document. If ``False``
100-
additionally sets ``wrap=False``. Default is ``True``.
91+
:param add_axis_environment: Whether ``'\\begin{axis}[...]'`` and ``'\\end{axis}'``
92+
will be written. One needs to set the environment in
93+
the document. If ``False`` additionally sets
94+
``wrap=False``. Default is ``True``.
10195
:type add_axis_environment: bool
10296
10397
:param extra_axis_parameters: Extra axis options to be passed (as a list or set)
@@ -144,8 +138,8 @@ def get_tikz_code(
144138
if figure == "gcf":
145139
figure = plt.gcf()
146140
data = {}
147-
data["fwidth"] = figurewidth
148-
data["fheight"] = figureheight
141+
data["axis width"] = axis_width
142+
data["axis height"] = axis_height
149143
data["rel data path"] = tex_relative_path_to_data
150144
data["externalize tables"] = externalize_tables
151145
data["override externals"] = override_externals

0 commit comments

Comments
 (0)