nschloe / tikzplotlib

:bar_chart: Save matplotlib figures as TikZ/PGFplots for smooth integration into LaTeX.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Rainbow scatter plot is produced, ignoring draw and fill options

8549 opened this issue · comments

commented

Python code

from sklearn import datasets, linear_model, neighbors
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd

plt.style.use('seaborn')

boston = datasets.load_boston()
df = pd.DataFrame(boston.data, columns=boston.feature_names)
df['MEDV'] = boston.target

X = df['LSTAT'].values.reshape(-1, 1)
y = df['MEDV']

plt.scatter(X, y)
import tikzplotlib
tikzplotlib.clean_figure()
tikzplotlib.save("test.tex")

output TeX

% This file was created by tikzplotlib v0.9.8.
\begin{tikzpicture}

\definecolor{color0}{rgb}{0.917647058823529,0.917647058823529,0.949019607843137}
\definecolor{color1}{rgb}{0.298039215686275,0.447058823529412,0.690196078431373}

\begin{axis}[
axis background/.style={fill=color0},
axis line style={white},
tick align=outside,
tick pos=left,
x grid style={white},
xmajorgrids,
xmin=-0.0820000000000003, xmax=39.782,
xtick style={color=white!15!black},
y grid style={white},
ymajorgrids,
ymin=2.75, ymax=52.25,
ytick style={color=white!15!black}
]
\addplot [draw=color1, fill=color1, mark=*, only marks, scatter]
table{%
x  y
4.98 24
9.14 21.6
4.03 34.7
2.94 33.4
5.33 36.2
5.21 28.7
12.43 22.9
19.15 27.1
29.93 16.5
17.1 18.9
20.45 15
13.27 18.9
15.71 21.7
8.26 20.4
10.26 18.2
8.47 19.9
6.58 23.1
14.67 17.5
11.69 20.2
11.28 18.2
21.02 13.6
13.83 19.6
18.72 15.2
19.88 14.5
16.3 15.6
16.51 13.9
14.81 16.6
17.28 14.8
12.8 18.4
11.98 21
22.6 12.7
13.04 14.5
27.71 13.2
18.35 13.1
20.34 13.5
9.68 18.9
11.41 20
8.77 21
10.13 24.7
4.32 30.8
1.98 34.9
4.84 26.6
5.81 25.3
7.44 24.7
9.55 21.2
10.21 19.3
14.15 20
18.8 16.6
30.81 14.4
16.2 19.4
13.45 19.7
9.43 20.5
5.28 25
8.43 23.4
14.8 18.9
4.81 35.4
5.77 24.7
3.95 31.6
6.86 23.3
9.22 19.6
13.15 18.7
14.44 16
6.73 22.2
9.5 25
8.05 33
4.67 23.5
10.24 19.4
8.1 22
13.09 17.4
8.79 20.9
6.72 24.2
9.88 21.7
5.52 22.8
7.54 23.4
6.78 24.1
8.94 21.4
11.97 20
10.27 20.8
12.34 21.2
9.1 20.3
5.29 28
7.22 23.9
6.72 24.8
7.51 22.9
9.62 23.9
6.53 26.6
12.86 22.5
8.44 22.2
5.5 23.6
5.7 28.7
8.81 22.6
8.2 22
8.16 22.9
6.21 25
10.59 20.6
6.65 28.4
11.34 21.4
4.21 38.7
3.57 43.8
6.19 33.2
9.42 27.5
7.67 26.5
10.63 18.6
13.44 19.3
12.33 20.1
16.47 19.5
18.66 19.5
14.09 20.4
12.27 19.8
15.55 19.4
13 21.7
10.16 22.8
16.21 18.8
17.09 18.7
10.45 18.5
15.76 18.3
12.04 21.2
10.3 19.2
15.37 20.4
13.61 19.3
14.37 22
14.27 20.3
17.93 20.5
25.41 17.3
17.58 18.8
14.81 21.4
27.26 15.7
17.19 16.2
15.39 18
18.34 14.3
12.6 19.2
12.26 19.6
11.12 23
15.03 18.4
17.31 15.6
16.96 18.1
16.9 17.4
14.59 17.1
21.32 13.3
18.46 17.8
24.16 14
34.41 14.4
26.82 13.4
26.42 15.6
29.29 11.8
27.8 13.8
16.65 15.6
29.53 14.6
28.32 17.8
21.45 15.4
14.1 21.5
13.28 19.6
12.12 15.3
15.79 19.4
15.12 17
15.02 15.6
16.14 13.1
4.59 41.3
6.43 24.3
7.39 23.3
5.5 27
1.73 50
1.92 50
3.32 50
11.64 22.7
9.81 25
3.7 50
12.14 23.8
11.1 23.8
11.32 22.3
14.43 17.4
12.03 19.1
14.69 23.1
9.04 23.6
9.64 22.6
5.33 29.4
10.11 23.2
6.29 24.6
6.92 29.9
5.04 37.2
7.56 39.8
9.45 36.2
4.82 37.9
5.68 32.5
13.98 26.4
13.15 29.6
4.45 50
6.68 32
4.56 29.8
5.39 34.9
5.1 37
4.69 30.5
2.87 36.4
5.03 31.1
4.38 29.1
2.97 50
4.08 33.3
8.61 30.3
6.62 34.6
4.56 34.9
4.45 32.9
7.43 24.1
3.11 42.3
3.81 48.5
2.88 50
10.87 22.6
10.97 24.4
18.06 22.5
14.66 24.4
23.09 20
17.27 21.7
23.98 19.3
16.03 22.4
9.38 28.1
29.55 23.7
9.47 25
13.51 23.3
9.69 28.7
17.92 21.5
10.5 23
9.71 26.7
21.46 21.7
9.93 27.5
7.6 30.1
4.14 44.8
4.63 50
3.13 37.6
6.36 31.6
3.92 46.7
3.76 31.5
11.65 24.3
5.25 31.7
2.47 41.7
3.95 48.3
8.05 29
10.88 24
9.54 25.1
4.73 31.5
6.36 23.7
7.37 23.3
11.38 22
12.4 20.1
11.22 22.2
5.19 23.7
12.5 17.6
18.46 18.5
9.16 24.3
10.15 20.5
9.52 24.5
6.56 26.2
5.9 24.4
3.59 24.8
3.53 29.6
3.54 42.8
6.57 21.9
9.25 20.9
3.11 44
5.12 50
7.79 36
6.9 30.1
9.59 33.8
7.26 43.1
5.91 48.8
11.25 31
8.1 36.5
10.45 22.8
14.79 30.7
7.44 50
3.16 43.5
13.65 20.7
13 21.1
6.59 25.2
7.73 24.4
6.58 35.2
3.53 32.4
2.98 32
6.05 33.2
4.16 33.1
7.19 29.1
4.85 35.1
3.76 45.4
4.59 35.4
3.01 46
3.16 50
7.85 32.2
8.23 22
12.93 20.1
7.14 23.2
7.6 22.3
9.51 24.8
3.33 28.5
3.56 37.3
4.7 27.9
8.58 23.9
10.4 21.7
6.27 28.6
7.39 27.1
15.84 20.3
4.97 22.5
4.74 29
6.07 24.8
9.5 22
8.67 26.4
4.86 33.1
6.93 36.1
8.93 28.4
6.47 33.4
7.53 28.2
4.54 22.8
9.97 20.3
12.64 16.1
5.98 22.1
11.72 19.4
7.9 21.6
9.28 23.8
11.5 16.2
18.33 17.8
15.94 19.8
10.36 23.1
12.73 21
7.2 23.8
6.87 23.1
7.7 20.4
11.74 18.5
6.12 25
5.08 24.6
6.15 23
12.79 22.2
9.97 19.3
7.34 22.6
9.09 19.8
12.43 17.1
7.83 19.4
5.68 22.2
6.75 20.7
8.01 21.1
9.8 19.5
10.56 18.5
8.51 20.6
9.74 19
9.29 18.7
5.49 32.7
8.65 16.5
7.18 23.9
4.61 31.2
10.53 17.5
12.67 17.2
6.36 23.1
5.99 24.5
5.89 26.6
5.98 22.9
5.49 24.1
7.79 18.6
4.5 30.1
8.05 18.2
5.57 20.6
17.6 17.8
13.27 21.7
11.48 22.7
12.67 22.6
7.79 25
14.19 19.9
10.19 20.8
14.64 16.8
5.29 21.9
7.12 27.5
14 21.9
13.33 23.1
3.26 50
3.73 50
2.96 50
9.53 50
8.88 50
34.77 13.8
37.97 13.8
13.44 15
23.24 13.9
21.24 13.3
23.69 13.1
21.78 10.2
17.21 10.4
21.08 10.9
23.6 11.3
24.56 12.3
30.63 8.8
30.81 7.2
28.28 10.5
31.99 7.4
30.62 10.2
20.85 11.5
17.11 15.1
18.76 23.2
25.68 9.7
15.17 13.8
16.35 12.7
17.12 13.1
19.37 12.5
19.92 8.5
30.59 5
29.97 6.3
26.77 5.6
20.32 7.2
20.31 12.1
19.77 8.3
27.38 8.5
22.98 5
23.34 11.9
12.13 27.9
26.4 17.2
19.78 27.5
10.11 15
21.22 17.2
34.37 17.9
20.08 16.3
36.98 7
29.05 7.2
25.79 7.5
26.64 10.4
20.62 8.8
22.74 8.4
15.02 16.7
15.7 14.2
14.1 20.8
23.29 13.4
17.16 11.7
24.39 8.3
15.69 10.2
14.52 10.9
21.52 11
24.08 9.5
17.64 14.5
19.69 14.1
12.03 16.1
16.22 14.3
15.17 11.7
23.27 13.4
18.05 9.6
26.45 8.7
34.02 8.4
22.88 12.8
22.11 10.5
19.52 17.1
16.59 18.4
18.85 15.4
23.79 10.8
23.98 11.8
17.79 14.9
16.44 12.6
18.13 14.1
19.31 13
17.44 13.4
17.73 15.2
17.27 16.1
16.74 17.8
18.71 14.9
18.13 14.1
19.01 12.7
16.94 13.5
16.23 14.9
14.7 20
16.42 16.4
14.65 17.7
13.99 19.5
10.29 20.2
13.22 21.4
14.13 19.9
17.15 19
21.32 19.1
18.13 19.1
14.76 20.1
16.29 19.9
12.87 19.6
14.36 23.2
11.66 29.8
18.14 13.8
24.1 13.3
18.68 16.7
24.91 12
18.03 14.6
13.11 21.4
10.74 23
7.74 23.7
7.01 25
10.42 21.8
13.34 20.6
10.58 21.2
14.98 19.1
11.45 20.6
18.06 15.2
23.97 7
29.68 8.1
18.07 13.6
13.35 20.1
12.01 21.8
13.59 24.5
17.6 23.1
21.14 19.7
14.1 18.3
12.92 21.2
15.1 17.5
14.33 16.8
9.67 22.4
9.08 20.6
5.64 23.9
6.48 22
7.88 11.9
};
\end{axis}

\end{tikzpicture}

which is rendered into:
image

Expected TeX

Non-rainbow marker points on the scatter that override the seaborn style. I managed to avoid the rainbow coloring by manually removing the scatter keyword from the \addplot command options (but I don't know if it's the proper way of doing it)

I did face the same issue.
You can use plt.plot() with the marker set to ".", "o" or "x" as a workaround.

I managed to avoid the rainbow coloring by manually removing the scatter keyword from the \addplot command options (but I don't know if it's the proper way of doing it)

Yes it is, for a detailed explanation see #479