Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I want to create a plot with predefined colors and have the points connected by a spline curve.

Both things do not happen. The color series is not applied (all lines are black) and a spline is not applied to the curve.

\documentclass[]{scrbook}

\usepackage{pgfplots}
\usetikzlibrary{pgfplots.patchplots}

\definecolor{colorseriesRGB1}{RGB}{0,     0, 192}
\definecolor{colorseriesRGB2}{RGB}{192,   0,   0}
\definecolor{colorseriesRGB3}{RGB}{0  , 128,   0}
\definecolor{colorseriesRGB4}{RGB}{192,   0, 192}

\pgfplotscreateplotcyclelist{colorseries-rgb}{
  {colorseriesRGB1},
  {colorseriesRGB2},
  {colorseriesRGB3},
  {colorseriesRGB4},
}

\begin{document}
\pgfplotsset{width=0.8\textwidth, height=0.6\textwidth}
\begin{tikzpicture}
\begin{axis}[cycle list name=colorseries-rgb]
\addplot[samples = 10,patch type=quadratic spline] {x^2 - x +4};
\end{axis}
\end{tikzpicture}
\end{document}

enter image description here

EDIT:

My original code is using a datatable. If I add the options mesh,patch,patch type=quadratic spline then the plot looks completely wrong

\begin{tikzpicture}
\begin{axis}[scale only axis,
             every axis plot/.append 
               style={line width=1.5pt},
             mark=none,
             style=solid,
             enlargelimits=false, ymax = 3.5,
             cycle list name=colorseries-office,
             % smooth,
             mesh,patch,patch type=quadratic spline
             ]
  %  column with header  "y1"
  \addplot+   table[x=x1,y=y1]  from  \datatable;
  \addplot+   table[x=x1,y=y2]  from  \datatable;
  \addplot+   table[x=x1,y=y3]  from  \datatable;
  \addplot+   table[x=x1,y=y4]  from  \datatable;
\end{axis}
\end{tikzpicture}

enter image description here

However the option smooth, although I have no idea what it really does looks like what I want:

enter image description here

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

If you have no optional arguments, then simply using

\addplot {x^2 - x +4};

will inherit the correct styles that you have specified. However, if you wish to override some of the arguments but keep the other aspects (as you have done in your code), then you have to use \addplot+[...

\addplot+[samples = 10] {x^2 - x +4};

which tells pgfplots to use the styles specified in cyclelist, but change the options that you have specified.

See Section 4.6.7 for more examples.

With regards to the quadratic spline, referencing Section 5.6.1,

The quadratic spline is actually nothing but piecewise Lagrangian interpolation with quadratic polynomials: it expects three points in the sequence ‘(left end), (right end), (middle)’ and interpolates these three points with a quadratic polynomial.

As such, for your example you can use something like

% left, right, middle
\addplot+[patch,mesh,patch type=quadratic spline]coordinates{(-5,33)(5,23)(0,3)};

It seems like you're currently trying to feed a function in to help find the coordinates- I don't know how to do this, but perhaps one of the gurus on this site will.

share|improve this answer
    
The + gives me a blue line, but the lines still appear not as a curve without edges, so no spline is applied. –  Matthias Pospiech Mar 18 '12 at 21:36
    
@MatthiasPospiech see my edit –  cmhughes Mar 18 '12 at 21:48
    
What I was looking for seems to be the option smooth, but then I do not understand the meaning of patch at all. If I also add the option patch, then my line is dashed and with variing colors in a line. –  Matthias Pospiech Mar 18 '12 at 21:56
    
@cmhughes Add smooth? –  Yiannis Lazarides Mar 18 '12 at 21:56
    
@MatthiasPospiech AFAIK smooth and patch are for situations where you have coordinates; if you have the formula, why not just increase samples? –  cmhughes Mar 18 '12 at 21:59
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.