我使用 matlab 绘制了一个图。然后.tikz
使用 matlab2tikz 生成了一个文件。现在我想在.tikz
文件中插入箭头,并在箭头左侧写一些内容。
我可以在图中制作箭头和文本,但 matlab2tikz 不知道文本框。所以这不起作用。
这是我的.tikz
文件:
% Copyright (c) 2008--2012, Nico Schlömer <[email protected]>
% All rights reserved.
%
% The latest updates can be retrieved from
% http://www.mathworks.com/matlabcentral/fileexchange/22022-matlab2tikz
% where you can also make suggestions and rate matlab2tikz.
%
%
%
\begin{tikzpicture}
\begin{axis}[%
view={0}{90},
width=\figurewidth,
height=\figureheight,
scale only axis,
xmin=257.75, xmax=260.4,
xlabel={[t] = s},
ymin=67.3, ymax=70.5,
ylabel={[v] = km/h},
axis lines=left,
legend style={at={(0.03,0.97)},anchor=north west,nodes=right}]
\addplot [
color=blue,
solid,
line width=1.5pt
]
coordinates{
(257.74,67.3076923076185)(257.75,67.323076923002)(257.76,67.3384615383854)(257.77,67.3538461537689)(257.78,67.3692307691524)(257.79,67.384615384536)(257.8,67.3999999999195)(257.81,67.4153846153031)(257.82,67.4462107691739)(257.83,67.4617649792577)(257.84,67.4774300990224)(257.85,67.4932043665521)(257.86,67.5090860199309)(257.87,67.5250732972429)(257.88,67.5411644365725)(257.89,67.5573576760036)(257.9,67.5736512536205)(257.91,67.5900434075073)(257.92,67.6065323757482)(257.93,67.6231163964273)(257.94,67.6397937076289)(257.95,67.656562547437)(257.96,67.6734211539357)(257.97,67.6903677652094)(257.98,67.7074006193421)(257.99,67.724517954418)(258,67.7417180085212)(258.01,67.7589990197359)(258.02,67.7763592261463)(258.03,67.7937968658364)(258.04,67.8113101768906)(258.05,67.8288973973929)(258.06,67.8465567654274)(258.07,67.8642865190784)(258.08,67.88208489643)(258.09,67.8999501355664)(258.1,67.9178804745717)(258.11,67.9358741515301)(258.12,67.9539294045257)(258.13,67.9720444716427)(258.14,67.9902175909652)(258.15,68.0084470005775)(258.16,68.0267309385636)(258.17,68.0450676430077)(258.18,68.063455351994)(258.19,68.0818923036067)(258.2,68.1003767359298)(258.21,68.1189068870476)(258.22,68.1374809950442)(258.23,68.1560972980038)(258.24,68.1747540340105)(258.25,68.1934494411485)(258.26,68.2121817575019)(258.27,68.2309492211549)(258.28,68.2497500701917)(258.29,68.2685825426964)(258.3,68.2874448767532)(258.31,68.3063353104462)(258.32,68.3252520818596)(258.33,68.3441934290775)(258.34,68.3631575901841)(258.35,68.3821428032636)(258.36,68.4011473064001)(258.37,68.4201693376778)(258.38,68.4392071351808)(258.39,68.4582589369933)(258.4,68.4773229811995)(258.41,68.4963975058835)(258.42,68.5154807491294)(258.43,68.5345709490215)(258.44,68.5536663436438)(258.45,68.5727651710806)(258.46,68.5918656694159)(258.47,68.6109660767341)(258.48,68.6300646311191)(258.49,68.6491595706552)(258.5,68.6682491334265)(258.51,68.6873315575172)(258.52,68.7064050810115)(258.53,68.7254679419934)(258.54,68.7445183785472)(258.55,68.763554628757)(258.56,68.782574930707)(258.57,68.8015775224814)(258.58,68.8205606421642)(258.59,68.8395225278396)(258.6,68.8584614175919)(258.61,68.8773755495051)(258.62,68.8962631616634)(258.63,68.9151224921511)(258.64,68.9339517790521)(258.65,68.9527492604507)(258.66,68.9715131744311)(258.67,68.9902417590774)(258.68,69.0089332524738)(258.69,69.0275858927044)(258.7,69.0461979178533)(258.71,69.0647675660048)(258.72,69.083293075243)(258.73,69.1017726836521)(258.74,69.1202046293161)(258.75,69.1385871503194)(258.76,69.1569184847459)(258.77,69.17519687068)(258.78,69.1934205462056)(258.79,69.2115877494071)(258.8,69.2296967183686)(258.81,69.2477456911741)(258.82,69.2657329059079)(258.83,69.2836566006542)(258.84,69.301515013497)(258.85,69.3193063825206)(258.86,69.3370289458091)(258.87,69.3546809414467)(258.88,69.3722606075174)(258.89,69.3897661821056)(258.9,69.4071959032953)(258.91,69.4245480091707)(258.92,69.4418207378159)(258.93,69.4590123273151)(258.94,69.4761210157525)(258.95,69.4931450412122)(258.96,69.5100826417784)(258.97,69.5269320555353)(258.98,69.5436915205669)(258.99,69.5603592749575)(259,69.5769335567912)(259.01,69.5934126041521)(259.02,69.6097946551245)(259.03,69.6260779477925)(259.04,69.6422607202402)(259.05,69.6583412105518)(259.06,69.6743176568115)(259.07,69.6901882971034)(259.08,69.7059513695117)(259.09,69.7216051121205)(259.1,69.7371477630139)(259.11,69.7525775602763)(259.12,69.7678927419916)(259.13,69.7830915462441)(259.14,69.7981722111179)(259.15,69.8131329746972)(259.16,69.8279720750661)(259.17,69.8426877503088)(259.18,69.8572782385095)(259.19,69.8717417777523)(259.2,69.8860766061213)(259.21,69.9002809617008)(259.22,69.9143530825748)(259.23,69.9282912068276)(259.24,69.9420935725433)(259.25,69.955758417806)(259.26,69.9692839806999)(259.27,69.9826684993092)(259.28,69.9959102117181)(259.29,70.0090073560106)(259.3,70.021958170271)(259.31,70.0347608925833)(259.32,70.0474137610318)(259.33,70.0599150137007)(259.34,70.072262888674)(259.35,70.0844556240359)(259.36,70.0964914578707)(259.37,70.1083686282623)(259.38,70.1200853732951)(259.39,70.1316399310532)(259.4,70.1430305396206)(259.41,70.1542554370817)(259.42,70.1653128615204)(259.43,70.1762010510211)(259.44,70.1869182436678)(259.45,70.1974626775447)(259.46,70.207832590736)(259.47,70.2180262213258)(259.48,70.2280418073983)(259.49,70.2378775870376)(259.5,70.247531798328)(259.51,70.2570026793534)(259.52,70.2662884681982)(259.53,70.2753874029465)(259.54,70.2842977216824)(259.55,70.2930176624901)(259.56,70.3015454634537)(259.57,70.3098793626574)(259.58,70.3180175981854)(259.59,70.3259584081218)(259.6,70.3337000305507)(259.61,70.3412407035564)(259.62,70.348578665223)(259.63,70.3557121536346)(259.64,70.3626394068754)(259.65,70.3693586630296)(259.66,70.3758681601814)(259.67,70.3821661364148)(259.68,70.388250829814)(259.69,70.3941204784632)(259.7,70.3997733204466)(259.71,70.4052075938482)(259.72,70.4104215367524)(259.73,70.4154133872431)(259.74,70.4201813834047)(259.75,70.4247237633212)(259.76,70.4290387650768)(259.77,70.4331246267556)(259.78,70.4369795864419)(259.79,70.4406018822197)(259.8,70.4439897521732)(259.81,70.4471414343867)(259.82,69.8513234785254)(259.83,69.8542387044367)(259.84,69.8570967690556)(259.85,69.8598987931917)(259.86,69.8626458756782)(259.87,69.8653390938021)(259.88,69.8679795037276)(259.89,69.8705681409094)(259.9,69.8731060204994)(259.91,69.8755941377445)(259.92,69.878033468377)(259.93,69.880424968997)(259.94,69.8827695774481)(259.95,69.8850682131844)(259.96,69.8873217776318)(259.97,69.8895311545409)(259.98,69.8916972103342)(259.99,69.8938207944453)(260,69.8959027396523)(260.01,69.8979438624042)(260.02,69.8999449631414)(260.03,69.9019068266092)(260.04,69.9038302221659)(260.05,69.9057159040842)(260.06,69.9075646118472)(260.07,69.9093770704385)(260.08,69.9111539906259)(260.09,69.9128960692411)(260.1,69.9146039894521)(260.11,69.9162784210315)(260.12,69.9179200206191)(260.13,69.9195294319795)(260.14,69.9211072862544)(260.15,69.9226542022102)(260.16,69.9241707864806)(260.17,69.9256576338045)(260.18,69.9271153272593)(260.19,69.9285444384895)(260.2,69.9299455279309)(260.21,69.9313191450303)(260.22,69.932665828461)(260.23,69.9339861063344)(260.24,69.9352804964062)(260.25,69.9365495062806)(260.26,69.9377936336084)(260.27,69.9390133662828)(260.28,69.9402091826302)(260.29,69.9413815515982)(260.3,69.9425309329394)(260.31,69.9436577773916)(260.32,69.9447625268545)(260.33,69.9458456145632)(260.34,69.9469074652581)(260.35,69.947948495351)(260.36,69.9489691130893)(260.37,69.949969718715)(260.38,69.9509507046225)(260.39,69.9519124555123)
};
\addlegendentry{$\text{v}_{\text{ang}}$};
\addplot [
color=green!50!black,
solid,
line width=1.5pt
]
coordinates{
(257.74,67.3076923076185)(257.75,67.323076923002)(257.76,67.3384615383854)(257.77,67.3538461537689)(257.78,67.3692307691524)(257.79,67.384615384536)(257.8,67.3999999999195)(257.81,67.4153846153031)(257.82,67.4307692306867)(257.83,67.4461538460703)(257.84,67.4615384614539)(257.85,67.4769230768376)(257.86,67.4923076922213)(257.87,67.507692307605)(257.88,67.5230769229887)(257.89,67.5384615383724)(257.9,67.5538461537561)(257.91,67.5692307691399)(257.92,67.5846153845237)(257.93,67.5999999999075)(257.94,67.6153846152912)(257.95,67.6307692306751)(257.96,67.6461538460589)(257.97,67.6615384614428)(257.98,67.6769230768266)(257.99,67.6923076922105)(258,67.7076923075944)(258.01,67.7230769229783)(258.02,67.7384615383623)(258.03,67.7538461537462)(258.04,67.7692307691302)(258.05,67.7846153845141)(258.06,67.7999999998981)(258.07,67.8153846152821)(258.08,67.8307692306661)(258.09,67.8461538460501)(258.1,67.8615384614341)(258.11,67.8769230768181)(258.12,67.8923076922022)(258.13,67.9076923075862)(258.14,67.9230769229703)(258.15,67.9384615383544)(258.16,67.9538461537385)(258.17,67.9692307691226)(258.18,67.9846153845067)(258.19,67.9999999998908)(258.2,68.0153846152749)(258.21,68.030769230659)(258.22,68.0461538460432)(258.23,68.0615384614274)(258.24,68.0769230768115)(258.25,68.0923076921957)(258.26,68.1076923075799)(258.27,68.1230769229641)(258.28,68.1384615383483)(258.29,68.1538461537325)(258.3,68.1692307691167)(258.31,68.1846153845009)(258.32,68.1999999998851)(258.33,68.2153846152694)(258.34,68.2307692306536)(258.35,68.2461538460379)(258.36,68.2615384614221)(258.37,68.2769230768064)(258.38,68.2923076921906)(258.39,68.3076923075749)(258.4,68.3230769229592)(258.41,68.3384615383435)(258.42,68.3538461537278)(258.43,68.3692307691121)(258.44,68.3846153844964)(258.45,68.3999999998807)(258.46,68.415384615265)(258.47,68.4307692306493)(258.48,68.4461538460337)(258.49,68.461538461418)(258.5,68.4769230768023)(258.51,68.4923076921867)(258.52,68.507692307571)(258.53,68.5230769229554)(258.54,68.5384615383397)(258.55,68.5538461537241)(258.56,68.5692307691085)(258.57,68.5846153844928)(258.58,68.5999999998772)(258.59,68.6153846152616)(258.6,68.630769230646)(258.61,68.6461538460304)(258.62,68.6615384614148)(258.63,68.6769230767992)(258.64,68.6923076921836)(258.65,68.707692307568)(258.66,68.7230769229524)(258.67,68.7384615383369)(258.68,68.7538461537213)(258.69,68.7692307691057)(258.7,68.7846153844901)(258.71,68.7999999998745)(258.72,68.8153846152589)(258.73,68.8307692306434)(258.74,68.8461538460278)(258.75,68.8615384614123)(258.76,68.8769230767967)(258.77,68.8923076921812)(258.78,68.9076923075656)(258.79,68.9230769229501)(258.8,68.9384615383345)(258.81,68.953846153719)(258.82,68.9692307691035)(258.83,68.9846153844879)(258.84,68.9999999998724)(258.85,69.0153846152568)(258.86,69.0307692306413)(258.87,69.0461538460258)(258.88,69.0615384614103)(258.89,69.0769230767948)(258.9,69.0923076921792)(258.91,69.1076923075637)(258.92,69.1230769229482)(258.93,69.1384615383327)(258.94,69.1538461537172)(258.95,69.1692307691017)(258.96,69.1846153844862)(258.97,69.1999999998707)(258.98,69.2153846152552)(258.99,69.2307692306397)(259,69.2458521869017)(259.01,69.2606393989232)(259.02,69.275136665611)(259.03,69.2893496721676)(259.04,69.3032839923212)(259.05,69.316945090511)(259.06,69.3303383240304)(259.07,69.3434689451278)(259.08,69.3563421030665)(259.09,69.3689628461436)(259.1,69.3813361236702)(259.11,69.3934667879119)(259.12,69.4053595959921)(259.13,69.417019211757)(259.14,69.4284502076049)(259.15,69.4396570662793)(259.16,69.4506441826267)(259.17,69.4614158653203)(259.18,69.4719763385494)(259.19,69.4823297436758)(259.2,69.4924801408587)(259.21,69.5024315106457)(259.22,69.512187755535)(259.23,69.5217527015049)(259.24,69.5311300995146)(259.25,69.5403236269751)(259.26,69.5493368891913)(259.27,69.5581734207758)(259.28,69.5668366870351)(259.29,69.5753300853285)(259.3,69.5836569464005)(259.31,69.5918205356868)(259.32,69.5998240545949)(259.33,69.6076706417597)(259.34,69.6153633742742)(259.35,69.6229052688963)(259.36,69.6302992832316)(259.37,69.6375483168938)(259.38,69.6446552126409)(259.39,69.6516227574911)(259.4,69.6584536838148)(259.41,69.6651506704067)(259.42,69.671716343536)(259.43,69.6781532779764)(259.44,69.6844639980161)(259.45,69.6906509784472)(259.46,69.6967166455364)(259.47,69.7026633779769)(259.48,69.7084935078205)(259.49,69.7142093213926)(259.5,69.7198130601889)(259.51,69.7253069217538)(259.52,69.7306930605429)(259.53,69.7359735887676)(259.54,69.7411505772231)(259.55,69.7462260561011)(259.56,69.7512020157854)(259.57,69.7560804076327)(259.58,69.760863144738)(259.59,69.7655521026843)(259.6,69.7701491202787)(259.61,69.7746560002732)(259.62,69.7790745100718)(259.63,69.7834063824233)(259.64,69.7876533161013)(259.65,69.7918169765699)(259.66,69.7958989966371)(259.67,69.7999009770952)(259.68,69.8038244873483)(259.69,69.8076710660277)(259.7,69.8114422215958)(259.71,69.815139432937)(259.72,69.8187641499383)(259.73,69.8223177940571)(259.74,69.8258017588796)(259.75,69.8292174106662)(259.76,69.8325660888884)(259.77,69.8358491067534)(259.78,69.839067751719)(259.79,69.842223285999)(259.8,69.8453169470579)(259.81,69.8483499480959)(259.82,69.8513234785254)(259.83,69.8542387044367)(259.84,69.8570967690556)(259.85,69.8598987931917)(259.86,69.8626458756782)(259.87,69.8653390938021)(259.88,69.8679795037276)(259.89,69.8705681409094)(259.9,69.8731060204994)(259.91,69.8755941377445)(259.92,69.878033468377)(259.93,69.880424968997)(259.94,69.8827695774481)(259.95,69.8850682131844)(259.96,69.8873217776318)(259.97,69.8895311545409)(259.98,69.8916972103342)(259.99,69.8938207944453)(260,69.8959027396523)(260.01,69.8979438624042)(260.02,69.8999449631414)(260.03,69.9019068266092)(260.04,69.9038302221659)(260.05,69.9057159040842)(260.06,69.9075646118472)(260.07,69.9093770704385)(260.08,69.9111539906259)(260.09,69.9128960692411)(260.1,69.9146039894521)(260.11,69.9162784210315)(260.12,69.9179200206191)(260.13,69.9195294319795)(260.14,69.9211072862544)(260.15,69.9226542022102)(260.16,69.9241707864806)(260.17,69.9256576338045)(260.18,69.9271153272593)(260.19,69.9285444384895)(260.2,69.9299455279309)(260.21,69.9313191450303)(260.22,69.932665828461)(260.23,69.9339861063344)(260.24,69.9352804964062)(260.25,69.9365495062806)(260.26,69.9377936336084)(260.27,69.9390133662828)(260.28,69.9402091826302)(260.29,69.9413815515982)(260.3,69.9425309329394)(260.31,69.9436577773916)(260.32,69.9447625268545)(260.33,69.9458456145632)(260.34,69.9469074652581)(260.35,69.947948495351)(260.36,69.9489691130893)(260.37,69.949969718715)(260.38,69.9509507046225)(260.39,69.9519124555123)
};
\addlegendentry{$\text{v}_{\text{soll}}$};
\end{axis}
\end{tikzpicture}
答案1
正如您在README
文件中所读到的matlab2tikz github 位置生成的matlab2tikz
是要包含在文件中的文件tex
。 在您的例子中,您已决定不修复图形尺寸,您需要在外部文件中声明和设置\figurewidth
。\figureheight
这就是我在下一个代码中所做的
\documentclass[border=2mm,tikz]{standalone}
\usepackage{amsmath}
\usepackage{pgfplots}
\pgfplotsset{plot coordinates/math parser=false}
\newlength\figureheight %declares new dimensions
\newlength\figurewidth
\begin{document}
% Setting the figure dimensions is optional (see above).
\setlength\figureheight{4cm} %fixes figure dimensions
\setlength\figurewidth{6cm}
\input{myplot.tikz} %your plot is into file 'myplot.tikz'
\end{document}
产生
现在第二个问题是如何在图上绘制一些东西。一种可能性是将新TiKZ
命令添加到.tikz
文件,但每次想要更改原始图(来自 matlab)时,您都需要重新进行修改。
另一种可能性是使用 TikZ 在图像上绘图。这样,myplot.tikz
就被包含在一个TiKZ
节点中,并且您arrows
将在其上绘制。下一个代码显示如何使用 Caramdir 和 Jake 的解决方案来解决您的问题。
\documentclass[border=2mm,tikz]{standalone}
\usepackage{amsmath}
\usepackage{pgfplots}
\pgfplotsset{plot coordinates/math parser=false}
\newlength\figureheight
\newlength\figurewidth
\begin{document}
% Setting the figure dimensions is optional (see above).
\setlength\figureheight{4cm}
\setlength\figurewidth{6cm}
\begin{tikzpicture}
%
%The matlab2tikz plot is drawn as a node
%
\node[anchor=south west,inner sep=0] (myplot) at (0,0) {
\input{myplot.tikz}
};
%
% Some grid lines are drawn to help you placing your additions
%
\begin{scope}[x={(myplot.south east)}, y={(myplot.north west)}]
%
% Next three lines must be commented to obtain final result
%
\draw[xstep=.1,ystep=.1,help lines,gray!50] (0,0) grid (1,1);
\foreach \x in {0,1,...,9} { \node [anchor=north,font=\tiny] at (\x/10,0) {0.\x}; }
\foreach \y in {0,1,...,9} { \node [anchor=east,font=\tiny] at (0,\y/10) {0.\y}; }
%
% You can add what you want over the plot
%
\draw[<-,thick,red] (.43,.55)--(.7,.7)
node[right,draw=red,rounded corners,
text width=2cm,align=center,text=blue]
{something right of the arrow};
\end{scope}
\end{tikzpicture}
\end{document}
帮助热线的结果是
而最终结果如下
最后的评论:我一直在使用standalone
包,但一切都可以在任何文档类中完成。