質問

Do you know a simple way to draw arbitrary splines or lines in a plot-figure? I've got the following figure which I created in powerpoint with more or less arbitrary spline-curve (blue) but I'd like to do the same in MATLAB now because of a better look in the final plot-output.

I'm now wondering if I've got to manually "find" data-values to draw some sort of spline (which looks roughly like the blue one below) myself or if there's maybe a tool where I can simply insert some points into a plot interactively and there's a curve fitted though it to create something similar!?

The green and red lines I can figure out myself (probably also have to plot them manually, do I)?!?

Thanks in advance!


EDIT Okay I found a way myself doing it in MATLAB to gnerate a nice spline: Use splinetool, then either use an example or import some data and then you can interactively add and delete points until your spline looks roughly like it should. Then file->print to figure and then tools->edit plot! You can then delete everything you don't need, add title, xlabel and ylabel etc. and then export it to latex with e.g. matlab2tikz :-) Very nice stuff!!

役に立ちましたか?

解決

According the purpose, print nice plots for the thesis, I have some out-of-Matlab recommendations.

1) plot everything as usual, you get a figure handle and an axes handle

h = figure( ... )
a = gca

2) use the data cursor function of the figure window and interactively insert the base points for your later splines. You can additional points by right-click.

t = linspace(0,2*pi,1000);
[x y] = deal(sin(t),cos(t))

enter image description here

Later you delete the "visual" part of the data tip inside Illustrator/Inkscape, if you just want to keep the anchor point of the vector graphic to snap your splines.

There is also the possibility of custom data tips: Tutorial at Matlab Central

3) I once wrote a function to nicely plot Matlab figures as vector graphic based PDFs. You can specify height, width and how much white margin around you want. You just need to pass figure and axes handle and the name:

function saveFigure( fig_handle, axes_handle, name , height , width , margin)

set(axes_handle,'LooseInset',get(gca,'TightInset'));
set(fig_handle, 'Units','centimeters','PaperUnits','centimeters')

% the last two parameters of 'Position' define the figure size
set(fig_handle,'Position',[-margin -margin width height],...
       'PaperPosition',[0 0 width+margin height+margin],...
       'PaperSize',[width+margin height+margin],...
       'PaperPositionMode','auto',...
       'InvertHardcopy', 'on',...
       'Renderer','painters'...     %recommended if there are no alphamaps
   );
saveas(fig_handle,name,'pdf')

end

4) You get a PDF you could directly use for Latex - for use in MS Office use 'emf' ( Enhanced metafile) rather than 'pdf'. Open this file with Adobe Illustrator (preferable as it offers layers) or Inkskape (Open Source).

5) The datatips are recognized as graphical objects, you can catch them and draw a spline on them. For Illustrator I'd recommend to put the spline in another layer than the actual figure. Later you can just swap the figure and give the spline new anchor points. In Inkscape you could use the grouping function to keep everything together.

6) I'd say you save a lot of time over a only-Matlab-solution. Good look!

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top