2

I am aiming to establish a tikzpicture that have two curves, the first curve have the following X and Y values and the second curve have the following X and Y values all the values for both the X and Y axes range from 0 to 1. Now I found this example as a starting point but not sure how to modify it since it assume that the X values is the same for both curves and only Y axis differs. Is there a way to achieve my needs?

    \documentclass[12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{pgfplots}
\pgfplotsset{width=10cm,compat=1.14}
%enter the data sets as follows.

\begin{filecontents}{thu3.dat}
X Splits    Part1  Part2
1 Split-1     24    36
2 Split-2       24  34
3 Split-3       22  29
4 Split-4       25  31
5 Split-5   1   1
\end{filecontents}

\begin{document}

\begin{figure}[h!]


\begin{tikzpicture}
\begin{axis}[
axis lines=middle,
ymin=0,
x label style={at={(current axis.right of origin)},anchor=north, below=10mm},
title={\textbf{\textit{Accuracy}}},
    xlabel=Time,
  ylabel=No. of Channels,
  xticklabel style = {rotate=30,anchor=east},
   enlargelimits = false,
  xticklabels from table={thu3.dat}{Splits},xtick=data]
\addplot[orange,thick,mark=square*] table [y=Part1,x=X]{thu3.dat};
\addlegendentry{Part I}
\addplot[green,thick,mark=square*] table [y= Part2,x=X]{thu3.dat};
\addlegendentry{Part II}
\end{axis}
\end{tikzpicture}
\caption{Comparison between part 1 and part 2 on Thursday}
\end{figure}
\end{document}

Thanks

2
  • I honestly don't understand what you want, can you try to expand/clarify? Are you after something like this? tex.stackexchange.com/questions/401685/… – Torbjørn T. Apr 11 '18 at 12:07
  • @TorbjørnT. Thank you for your comment, I tried to clarify further my question. Please don't hesitate to ask if it was not clear. Thank you again. – User3700 Apr 11 '18 at 17:22
2

There are a couple of things to change:

From the axis options you want to remove these three things:

xticklabel style = {rotate=30,anchor=east},
xticklabels from table={thu3.dat}{Splits},
xtick=data

The first one is somewhat pointless here I think, as you only have numbers. The ticklabels aren't so long that rotating is needed. You don't want to read in the ticklabels from some file I think, I'm guessing you just want the numerical value. And the last one will place a tick at every single data point in the first \addplot, which is altogether too much.

For the \addplots themselves, you want

\addplot[orange,thick,mark=square*] table[col sep=comma] {Curve_one.csv};
\addplot[green,thick,mark=square*] table[col sep=comma] {Curve_two.csv};

possibly with other colours/markers, but that is for you to decide. The colour is set by orange/green, so to use a different colour just replace these by whatever colour you need. To get a thinner line you can just remove thick. (Or replace by thin, but I believe that is the default.) If you want to change the size of the markers (the squares), use mark size=1pt, where you modify 1pt to whatever you want.

Here I used the two datafiles you posted links to. pgfplots by default assumes that columns in datafiles are separated by whitespace, so col sep=comma is needed here. I haven't explicitly specified which column is x and which is y, because pgfplots will, unless told otherwise, use the first column for the x-values and the second for the y-values. And that is how those .csv files are structured.

To get the labels centered on the axes, the simplest solution is perhaps to change axis lines=middle to axis lines=left. That will also change another thing, giving you ticklabels for zero, on x- and y-axis. But you have in your code already a method for moving the axis labels, in your original code. So an alternative method would be this:

axis lines=middle,
x label style={at={(0.5,0)},below=2.5ex},
y label style={at={(0,0.5)},rotate=90,above=5ex},

enter image description here

\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{pgfplots}
\pgfplotsset{width=10cm,compat=1.14}
\definecolor{RYB1}{RGB}{218,232,252}
\definecolor{RYB3}{RGB}{108,142,191}
\begin{document}

\begin{figure}
\centering
\begin{tikzpicture}
\begin{axis}[
  % either use the following three lines
%  axis lines=middle,
%  x label style={at={(0.5,0)},below=2.5ex},
%  y label style={at={(0,0.5)},rotate=90,above=5ex},
  % or use this one line
  axis lines=left,
  ymin=0,
  title={\textbf{\textit{Accuracy}}},
  xlabel=Time,
  ylabel=No. of Channels,
  enlargelimits = false,
  legend pos=south east
]
\addplot[RYB1, mark=square*] table[col sep=comma] {Curve_one.csv};
\addlegendentry{Part I}
\addplot[RYB3, mark=square*] table[col sep=comma] {Curve_two.csv};
\addlegendentry{Part II}
\end{axis}
\end{tikzpicture}
\caption{Comparison between part 1 and part 2 on Thursday}
\end{figure}
\end{document}
4
  • Ineradicable that was really informative, thank you very much. – User3700 Apr 11 '18 at 18:04
  • excuse me for bothering, I added a few tiny modifications in a figure in the question if it is possible to do. Thank you very much Torbjørn T. – User3700 Apr 11 '18 at 20:16
  • @User3700 I'll edit soon. But if you look at \addplot[orange,thick,mark=square] .., what do you think you need to change to make it a different colour (than orange) and thin? Do you want to remove the markers? – Torbjørn T. Apr 11 '18 at 20:28
  • @User3700 I'm a bit baffled. You don't want to fill anything, so why do you think you should add fill=? Just replace orange with RYB1. – Torbjørn T. Apr 11 '18 at 20:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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