|
3 | 3 | import pathlib
|
4 | 4 | import tempfile
|
5 | 5 | import warnings
|
| 6 | +from typing import List, Optional, Set, Union |
6 | 7 |
|
7 | 8 | import matplotlib as mpl
|
8 | 9 | import matplotlib.pyplot as plt
|
|
17 | 18 |
|
18 | 19 | def get_tikz_code(
|
19 | 20 | figure="gcf",
|
20 |
| - filepath=None, |
21 |
| - axis_width=None, |
22 |
| - axis_height=None, |
23 |
| - textsize=10.0, |
24 |
| - tex_relative_path_to_data=None, |
25 |
| - externalize_tables=False, |
26 |
| - override_externals=False, |
27 |
| - strict=False, |
28 |
| - wrap=True, |
29 |
| - add_axis_environment=True, |
30 |
| - extra_axis_parameters=None, |
31 |
| - extra_groupstyle_parameters={}, |
32 |
| - extra_tikzpicture_parameters=None, |
33 |
| - dpi=None, |
34 |
| - show_info=False, |
35 |
| - include_disclaimer=True, |
36 |
| - standalone=False, |
37 |
| - float_format=".15g", |
38 |
| - table_row_sep="\n", |
39 |
| - flavor="latex", |
| 21 | + filepath: Optional[Union[str, pathlib.Path]] = None, |
| 22 | + axis_width: Optional[str] = None, |
| 23 | + axis_height: Optional[str] = None, |
| 24 | + textsize: float = 10.0, |
| 25 | + tex_relative_path_to_data: Optional[str] = None, |
| 26 | + externalize_tables: bool = False, |
| 27 | + override_externals: bool = False, |
| 28 | + strict: bool = False, |
| 29 | + wrap: bool = True, |
| 30 | + add_axis_environment: bool = True, |
| 31 | + extra_axis_parameters: Optional[Union[List, Set]] = None, |
| 32 | + extra_groupstyle_parameters: dict = {}, |
| 33 | + extra_tikzpicture_parameters: Optional[Union[List, Set]] = None, |
| 34 | + dpi: Optional[int] = None, |
| 35 | + show_info: bool = False, |
| 36 | + include_disclaimer: bool = True, |
| 37 | + standalone: bool = False, |
| 38 | + float_format: str = ".15g", |
| 39 | + table_row_sep: str = "\n", |
| 40 | + flavor: str = "latex", |
40 | 41 | ):
|
41 | 42 | """Main function. Here, the recursion into the image starts and the
|
42 | 43 | contents are picked up. The actual file gets written in this routine.
|
@@ -156,11 +157,12 @@ def get_tikz_code(
|
156 | 157 | if filepath:
|
157 | 158 | filepath = pathlib.Path(filepath)
|
158 | 159 | data["output dir"] = filepath.parent
|
| 160 | + data["base name"] = filepath.stem |
159 | 161 | else:
|
160 | 162 | directory = tempfile.mkdtemp()
|
161 | 163 | data["output dir"] = pathlib.Path(directory)
|
| 164 | + data["base name"] = "tmp" |
162 | 165 |
|
163 |
| - data["base name"] = filepath.stem if filepath else "tmp" |
164 | 166 | data["strict"] = strict
|
165 | 167 | data["tikz libs"] = set()
|
166 | 168 | data["pgfplots libs"] = set()
|
@@ -239,7 +241,9 @@ def get_tikz_code(
|
239 | 241 | return code
|
240 | 242 |
|
241 | 243 |
|
242 |
| -def save(filepath, *args, encoding=None, **kwargs): |
| 244 | +def save( |
| 245 | + filepath: Union[str, pathlib.Path], *args, encoding: Optional[str] = None, **kwargs |
| 246 | +): |
243 | 247 | """Same as `get_tikz_code()`, but actually saves the code to a file.
|
244 | 248 |
|
245 | 249 | :param filepath: The file to which the TikZ output will be written.
|
|
0 commit comments