Skip to content

Commit dda871d

Browse files
committed
use axis color labels
1 parent 4e752ca commit dda871d

12 files changed

+66
-43
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
runs-on: ubuntu-latest
2424
strategy:
2525
matrix:
26-
python-version: [3.6, 3.7, 3.8, 3.9]
26+
python-version: ["3.7", "3.8", "3.9", "3.10-dev"]
2727
steps:
2828
- uses: actions/setup-python@v2
2929
with:

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@ build/
1010
*.egg-info/
1111
.pytest_cache/
1212
.tox/
13+
mytikz.tex
14+
test.tex

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ repos:
55
- id: isort
66

77
- repo: https://github.com/psf/black
8-
rev: 21.8b0
8+
rev: 21.9b0
99
hooks:
1010
- id: black
1111
language_version: python3
1212

1313
- repo: https://github.com/PyCQA/flake8
14-
rev: 3.9.2
14+
rev: 4.0.1
1515
hooks:
1616
- id: flake8

README.md

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,9 @@ figures like
2626

2727
for native inclusion into LaTeX or ConTeXt documents.
2828

29-
The output of tikzplotlib is in
30-
[PGFPlots](https://github.com/pgf-tikz/pgfplots/), a TeX library that sits on
31-
top of [PGF/TikZ](https://en.wikipedia.org/wiki/PGF/TikZ) and describes graphs in terms
32-
of axes, data etc. Consequently, the output of tikzplotlib
29+
The output of tikzplotlib is in [PGFPlots](https://github.com/pgf-tikz/pgfplots/), a TeX
30+
library that sits on top of [PGF/TikZ](https://en.wikipedia.org/wiki/PGF/TikZ) and
31+
describes graphs in terms of axes, data etc. Consequently, the output of tikzplotlib
3332

3433
- retains more information,
3534
- can be more easily understood, and
@@ -58,14 +57,17 @@ import tikzplotlib
5857

5958
tikzplotlib.save("test.tex")
6059
```
60+
6161
<!--close the figure and reset defaults
6262
<!--pytest-codeblocks:cont-->
63+
6364
```python
6465
import matplotlib as mpl
6566

6667
plt.close()
6768
mpl.rcParams.update(mpl.rcParamsDefault)
6869
```
70+
6971
-->
7072
(see above) gives
7173

@@ -147,8 +149,8 @@ to install.
147149

148150
to store the TikZ file as `mytikz.tex`.
149151

150-
3. Add the contents of `mytikz.tex` into your TeX source code. A convenient way of
151-
doing so is via
152+
3. Add the contents of `mytikz.tex` into your TeX source code. A convenient way of doing
153+
so is via
152154

153155
```latex
154156
\input{/path/to/mytikz.tex}
@@ -189,7 +191,8 @@ to install.
189191
tikzplotlib.Flavors.context.preamble()
190192
```
191193

192-
4. Optional: clean up the figure before exporting to tikz using the `clean_figure` command.
194+
4. [Optional] Clean up the figure before exporting to tikz using the `clean_figure`
195+
command.
193196

194197
```python
195198
import matplotlib.pyplot as plt
@@ -212,16 +215,16 @@ to install.
212215

213216
### Contributing
214217

215-
If you experience bugs, would like to contribute, have nice examples of what
216-
tikzplotlib can do, or if you are just looking for more information, then please
217-
visit [tikzplotlib's GitHub page](https://github.com/nschloe/tikzplotlib).
218+
If you experience bugs, would like to contribute, have nice examples of what tikzplotlib
219+
can do, or if you are just looking for more information, then please visit
220+
[tikzplotlib's GitHub page](https://github.com/nschloe/tikzplotlib).
218221

219222
### Testing
220223

221224
tikzplotlib has automatic unit testing to make sure that the software doesn't
222225
accidentally get worse over time. In `test/`, a number of test cases are specified.
223-
Those run through tikzplotlib and compare the output with a previously stored
224-
reference TeX file.
226+
Those run through tikzplotlib and compare the output with a previously stored reference
227+
TeX file.
225228

226229
To run the tests, just check out this repository and type
227230

@@ -231,4 +234,5 @@ pytest
231234

232235
### License
233236

234-
tikzplotlib is published under the [MIT license](https://en.wikipedia.org/wiki/MIT_License).
237+
tikzplotlib is published under the [MIT
238+
license](https://en.wikipedia.org/wiki/MIT_License).

justfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ default:
77

88
tag:
99
@if [ "$(git rev-parse --abbrev-ref HEAD)" != "main" ]; then exit 1; fi
10-
curl -H "Authorization: token `cat ~/.github-access-token`" -d '{"tag_name": "{{version}}"}' https://api.github.com/repos/nschloe/{{name}}/releases
10+
curl -H "Authorization: token `cat ~/.github-access-token`" -d '{"tag_name": "v{{version}}"}' https://api.github.com/repos/nschloe/{{name}}/releases
1111

1212
upload: clean
1313
@if [ "$(git rev-parse --abbrev-ref HEAD)" != "main" ]; then exit 1; fi

setup.cfg

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = tikzplotlib
3-
version = 0.9.12
3+
version = 0.9.14
44
author = Nico Schlömer
55
author_email = [email protected]
66
description = Convert matplotlib figures into TikZ/PGFPlots
@@ -14,16 +14,16 @@ long_description_content_type = text/markdown
1414
license = MIT
1515
license_file = LICENSE
1616
classifiers =
17-
Development Status :: 4 - Beta
17+
Development Status :: 5 - Production/Stable
1818
Framework :: Matplotlib
1919
License :: OSI Approved :: MIT License
2020
Operating System :: OS Independent
2121
Programming Language :: Python
2222
Programming Language :: Python :: 3
23-
Programming Language :: Python :: 3.6
2423
Programming Language :: Python :: 3.7
2524
Programming Language :: Python :: 3.8
2625
Programming Language :: Python :: 3.9
26+
Programming Language :: Python :: 3.10
2727
Topic :: Multimedia :: Graphics :: Graphics Conversion
2828
Topic :: Scientific/Engineering :: Visualization
2929
keywords =
@@ -41,7 +41,7 @@ install_requires =
4141
matplotlib >= 1.4.0
4242
numpy
4343
Pillow
44-
python_requires = >=3.6
44+
python_requires = >=3.7
4545

4646
[options.packages.find]
4747
where=src

src/tikzplotlib/_axes.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,30 @@ def __init__(self, data, obj): # noqa: C901
4949
xlabel = obj.get_xlabel()
5050
if xlabel:
5151
xlabel = _common_texification(xlabel)
52-
self.axis_options.append(f"xlabel={{{xlabel}}}")
52+
53+
labelcolor = obj.xaxis.label.get_c()
54+
55+
if labelcolor != "black":
56+
data, col, _ = _color.mpl_color2xcolor(data, labelcolor)
57+
self.axis_options.append(f"xlabel=\\textcolor{{{col}}}{{{xlabel}}}")
58+
else:
59+
self.axis_options.append(f"xlabel={{{xlabel}}}")
60+
5361
xrotation = obj.xaxis.get_label().get_rotation()
5462
if xrotation != 0:
5563
self.axis_options.append(f"xlabel style={{rotate={xrotation - 90}}}")
64+
5665
ylabel = obj.get_ylabel()
5766
if ylabel:
5867
ylabel = _common_texification(ylabel)
59-
self.axis_options.append(f"ylabel={{{ylabel}}}")
68+
69+
labelcolor = obj.yaxis.label.get_c()
70+
if labelcolor != "black":
71+
data, col, _ = _color.mpl_color2xcolor(data, labelcolor)
72+
self.axis_options.append(f"ylabel=\\textcolor{{{col}}}{{{ylabel}}}")
73+
else:
74+
self.axis_options.append(f"ylabel={{{ylabel}}}")
75+
6076
yrotation = obj.yaxis.get_label().get_rotation()
6177
if yrotation != 90:
6278
self.axis_options.append(f"ylabel style={{rotate={yrotation - 90}}}")

src/tikzplotlib/_cleanfigure.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,9 @@ def _move_points_closer(xLim, yLim, data):
752752

753753
dataInsert = np.array([[]])
754754
if not _isempty(id_replace):
755-
raise NotImplementedError
755+
raise NotImplementedError(
756+
"There is data outside of the box. Don't know how to handle during cleaning. Please check if x/ylim is to tight"
757+
)
756758
data = _insert_data(data, id_replace, dataInsert)
757759
if _isempty(id_replace):
758760
return data

src/tikzplotlib/_save.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
from __future__ import annotations
2+
13
import enum
24
import pathlib
35
import tempfile
46
import warnings
5-
from typing import List, Optional, Set, Union
67

78
import matplotlib as mpl
89
import matplotlib.pyplot as plt
@@ -17,22 +18,22 @@
1718

1819
def get_tikz_code(
1920
figure="gcf",
20-
filepath: Optional[Union[str, pathlib.Path]] = None,
21-
axis_width: Optional[str] = None,
22-
axis_height: Optional[str] = None,
21+
filepath: str | pathlib.Path | None = None,
22+
axis_width: str | None = None,
23+
axis_height: str | None = None,
2324
textsize: float = 10.0,
24-
tex_relative_path_to_data: Optional[str] = None,
25+
tex_relative_path_to_data: str | None = None,
2526
externalize_tables: bool = False,
2627
override_externals: bool = False,
27-
externals_search_path: Optional[str] = None,
28+
externals_search_path: str | None = None,
2829
strict: bool = False,
2930
wrap: bool = True,
3031
add_axis_environment: bool = True,
31-
extra_axis_parameters: Optional[Union[List, Set]] = None,
32+
extra_axis_parameters: list | set | None = None,
3233
extra_groupstyle_parameters: dict = {},
33-
extra_tikzpicture_parameters: Optional[Union[List, Set]] = None,
34-
extra_lines_start: Optional[Union[List, Set]] = None,
35-
dpi: Optional[int] = None,
34+
extra_tikzpicture_parameters: list | set | None = None,
35+
extra_lines_start: list | set | None = None,
36+
dpi: int | None = None,
3637
show_info: bool = False,
3738
include_disclaimer: bool = True,
3839
standalone: bool = False,
@@ -246,9 +247,7 @@ def get_tikz_code(
246247
return code
247248

248249

249-
def save(
250-
filepath: Union[str, pathlib.Path], *args, encoding: Optional[str] = None, **kwargs
251-
):
250+
def save(filepath: str | pathlib.Path, *args, encoding: str | None = None, **kwargs):
252251
"""Same as `get_tikz_code()`, but actually saves the code to a file.
253252
254253
:param filepath: The file to which the TikZ output will be written.

tests/test_basic_sin_reference.tex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@
2020
tick pos=left,
2121
title={Simple plot \(\displaystyle \frac{\alpha}{2}\)},
2222
x grid style={white},
23-
xlabel={time(s)},
23+
xlabel=\textcolor{white!33.333333!black}{time(s)},
2424
xmajorgrids,
2525
xmin=-0.095, xmax=1.995,
2626
xtick style={color=white!33.333333!black},
2727
y grid style={white},
28-
ylabel={Voltage (mV)},
28+
ylabel=\textcolor{white!33.333333!black}{Voltage (mV)},
2929
ymajorgrids,
3030
ymin=-1.1, ymax=1.1,
3131
ytick style={color=white!33.333333!black}

0 commit comments

Comments
 (0)