Quantcast
Channel: Using MATLAB area() to shade graph error in matlab2tikz - TeX - LaTeX Stack Exchange
Viewing all articles
Browse latest Browse all 2

Using MATLAB area() to shade graph error in matlab2tikz

$
0
0

I generate a graph in MATLAB and want to shade regions. So I use the area() command and set it to display in the right order.

MATLAB code for the graph:

hold on x = 0:1:5;y = sin(x);plot(x,y);h(1) = area([0.2 0.8], [2 2],'EdgeColor',[1.0 0.8 0.4]);h(2) = area([0.8 1.5], [2 2],'EdgeColor',[1.0 0.6 0.2]);set(h(1),'FaceColor',[1.0 0.8 0.4]);set(h(2),'FaceColor',[1.0 0.6 0.2]);set(gca,'children',flipud(get(gca,'children')));

Makes this gorgeous plot:

enter image description here

Full latex MWE (the generated .tikz code from matlab2tikz will be between the tikzpicture environment:

\documentclass{article}\usepackage{pgfplots}\begin{document}\begin{figure}\begin{tikzpicture}\begin{axis}[%width=4.5in,height=3.5in,area style,stack plots=y,scale only axis,xmin=0,xmax=5,ymin=-1,ymax=2,axis x line*=bottom,axis y line*=left]\addplot[fill=white!20!orange,draw=white!20!orange] plot table[row sep=crcr]{0.8    2\\1.5 2\\}\closedcycle;\addplot[fill=mycolor1,draw=mycolor1] plot table[row sep=crcr]{0.2  2\\0.8 2\\}\closedcycle;\addplot [color=blue,solid,forget plot]  table[row sep=crcr]{0 0\\1   0.841470984807897\\2   0.909297426825682\\3   0.141120008059867\\4   -0.756802495307928\\5   -0.958924274663138\\};\end{axis}\end{tikzpicture}%\end{figure}\end{document}

When I try and compile it in latex I get the error:

! Package pgfplots Error: Sorry, pgfplots expects stacked plots to have exactlythe same number of coordinates.

I think this is a glitch in matlab2tikz so I will report it, but either way I do not know how to fix it for my example.

Thanks


Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images