nschloe/tikzplotlib

Tikz figure doesn't look like the matplotlib figure

de-gozaru opened this issue · 0 comments

Hi,

I'm new to using tikzplotlib. My issue is that the produced tikz figure in latex doesn't follow the style of the figure in matplotlib.
Here is a minimal example:

import numpy as np
import matplotlib.pyplot as plt
import tikzplotlib

plt.close('all')

fig, ax = plt.subplots(figsize=(3.29, 2.05))

x = np.linspace(1, 6, 100)
ax.plot(x, np.sin(x), linestyle='-', label="sin", alpha=1)
ax.plot(x, np.cos(x), linestyle='-', label="cos", alpha=1)

ax.set_xlim([1, 6.0])
ax.set_ylim([-1.1, 1.1])
ax.set_title("Figure Title ", fontweight='bold')
ax.set_xlabel('x axis')
ax.set_ylabel('y axis')


tikzplotlib.clean_figure()
tikzplotlib.save("./outputs/fig.tex")


plt.savefig('./outputs/fig.pdf', dpi=500)
plt.show()

Here is the image produced by matplotlib
image

and here is the image produced by Tikz
image

For example, you can see that the two figure doesn't have the same size and aspect ratio, the title is not in bold, there is an additional top and right border generated in Tiks, etc.

How can I make the two plots similar please?

Attached is the output of tikzplotlib.

Thank you in advance!

% This file was created with tikzplotlib v0.10.1.
\begin{tikzpicture}

\definecolor{darkgray177175181}{RGB}{177,175,181}
\definecolor{darkslategray504852}{RGB}{50,48,52}
\definecolor{orchid188128189}{RGB}{188,128,189}
\definecolor{salmon251128114}{RGB}{251,128,114}

\begin{axis}[
tick align=outside,
tick pos=left,
title={Figure Title },
x grid style={darkgray177175181},
xlabel={x axis},
xmin=1, xmax=6,
xtick style={color=darkslategray504852},
y grid style={darkgray177175181},
ylabel={y axis},
ymin=-1.1, ymax=1.1,
ytick style={color=darkslategray504852}
]
\addplot [line width=0.28pt, orchid188128189, opacity=1]
table {%
1 0.841470956802368
1.05050504207611 0.867674350738525
1.10101008415222 0.891665101051331
1.15151512622833 0.913381814956665
1.20202016830444 0.932769298553467
1.25252521038055 0.949777841567993
1.30303025245667 0.964364290237427
1.35353529453278 0.976491451263428
1.40404045581818 0.986128449440002
1.45454549789429 0.993250489234924
1.5050505399704 0.997839450836182
1.55555558204651 0.999883890151978
1.60606062412262 0.999378204345703
1.65656566619873 0.996324062347412
1.70707070827484 0.990729093551636
1.75757575035095 0.982607364654541
1.80808079242706 0.971979856491089
1.85858583450317 0.958873629570007
1.90909087657928 0.943321943283081
1.9595959186554 0.92536473274231
2.0101010799408 0.905047655105591
2.06060600280762 0.88242244720459
2.11111116409302 0.857546806335449
2.16161608695984 0.8304842710495
2.26262617111206 0.770079851150513
2.36363625526428 0.701825022697449
2.46464657783508 0.626415491104126
2.5656566619873 0.544620037078857
2.66666674613953 0.45727264881134
2.76767683029175 0.36526358127594
2.91919183731079 0.220571875572205
3.12121200561523 0.0203790664672852
3.37373733520508 -0.230065226554871
3.5252525806427 -0.374316811561584
3.62626266479492 -0.465916395187378
3.72727274894714 -0.5527663230896
3.82828283309937 -0.633980989456177
3.92929291725159 -0.708732724189758
4.03030300140381 -0.776259422302246
4.13131332397461 -0.835872650146484
4.18181800842285 -0.862518310546875
4.23232316970825 -0.886964559555054
4.28282833099365 -0.909148812294006
4.33333349227905 -0.929014444351196
4.38383817672729 -0.946511030197144
4.4343433380127 -0.961593747138977
4.4848484992981 -0.974224090576172
4.5353536605835 -0.984370112419128
4.5858588218689 -0.992005705833435
4.63636350631714 -0.997111439704895
4.68686866760254 -0.999674320220947
4.73737382888794 -0.999687910079956
4.78787899017334 -0.997151970863342
4.83838367462158 -0.992073059082031
4.88888883590698 -0.984464287757874
4.93939399719238 -0.974344849586487
4.98989915847778 -0.961740493774414
5.04040384292603 -0.946683645248413
5.09090900421143 -0.92921257019043
5.14141416549683 -0.909371614456177
5.19191932678223 -0.887211799621582
5.24242401123047 -0.862789273262024
5.29292917251587 -0.836166381835938
5.34343433380127 -0.807411193847656
5.44444465637207 -0.743802070617676
5.54545450210571 -0.672610402107239
5.64646482467651 -0.594561815261841
5.74747467041016 -0.510452270507812
5.84848499298096 -0.421138763427734
5.9494948387146 -0.327532052993774
6 -0.279415488243103
};
\addplot [line width=0.28pt, salmon251128114, opacity=1]
table {%
1 0.540302276611328
1.10101008415222 0.452695608139038
1.20202016830444 0.360474109649658
1.35353529453278 0.215555787086487
1.55555558204651 0.0152401924133301
1.80808079242706 -0.235064029693604
1.9595959186554 -0.379077911376953
2.06060600280762 -0.470458030700684
2.16161608695984 -0.557042121887207
2.26262617111206 -0.6379474401474
2.36363625526428 -0.712349414825439
2.46464657783508 -0.779489278793335
2.5656566619873 -0.838682889938354
2.61616158485413 -0.865107774734497
2.66666674613953 -0.889326572418213
2.71717166900635 -0.911277294158936
2.76767683029175 -0.930904150009155
2.81818175315857 -0.948156952857971
2.86868691444397 -0.962991714477539
2.91919183731079 -0.975370645523071
2.96969699859619 -0.985262274742126
3.02020192146301 -0.99264121055603
3.07070708274841 -0.997488737106323
3.12121200561523 -0.999792337417603
3.17171716690063 -0.99954628944397
3.22222232818604 -0.996751189231873
3.27272725105286 -0.991414189338684
3.32323241233826 -0.983548879623413
3.37373733520508 -0.973175287246704
3.42424249649048 -0.960319757461548
3.4747474193573 -0.94501531124115
3.5252525806427 -0.927300930023193
3.57575750350952 -0.907221555709839
3.62626266479492 -0.884828805923462
3.67676758766174 -0.860179424285889
3.72727274894714 -0.833336353302002
3.82828283309937 -0.773348569869995
3.92929291725159 -0.705476999282837
4.03030300140381 -0.63041365146637
4.13131332397461 -0.548923492431641
4.23232316970825 -0.461837530136108
4.33333349227905 -0.370043277740479
4.4848484992981 -0.225582122802734
4.68686866760254 -0.025517463684082
4.93939399719238 0.225060343742371
5.09090900421143 0.369545698165894
5.19191932678223 0.461362361907959
5.29292917251587 0.548475742340088
5.39393949508667 0.629997849464417
5.49494934082031 0.705097436904907
5.59595966339111 0.773009061813354
5.69696950912476 0.833040237426758
5.74747467041016 0.859906196594238
5.79797983169556 0.884579181671143
5.84848499298096 0.906996250152588
5.8989896774292 0.927100300788879
5.9494948387146 0.94484007358551
6 0.960170269012451
};
\end{axis}

\end{tikzpicture}