3

I have the following table to draw as a graph in LaTeX.

enter image description here

Notice that we don't have coordinates to be drawn. For each method, there is one accuracy value. For example the Method 1 has an accuracy equal to 1.454, the same for the other methods.

The question is how can I represent this table as a graph or curve showing the accuracy of each method ? For example the x-axis shows all the method possibilities (Method 1, Method 2, Method 3) while the accuracy values in the y-axis, etc. Kindly give me all the possibilities.

Any help will be very appreciated.

2 Answers 2

3

With pgfplots, using symbolic x coords.

enter image description here

\documentclass[border=10pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
  symbolic x coords={Method 1,Method 2, Method 3},
  xtick={Method 1,Method 2, Method 3},
  ytick={1.454,2.14,4.23},
  xticklabel style={rotate=-90},
  only marks, % removes lines between points
  ylabel={Accuracy}]

\addplot coordinates {(Method 1,1.454) (Method 2,2.14) (Method 3,4.23)};
\end{axis}
\end{tikzpicture}

\end{document}

Or as a barplot:

enter image description here

\documentclass[border=10pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
  ybar,
  symbolic x coords={Method 1,Method 2, Method 3},
  xtick={Method 1,Method 2, Method 3},
  nodes near coords,
%  ytick={1.454,2.14,4.23},
  xticklabel style={rotate=-90},
  ylabel={Accuracy}]

\addplot coordinates {(Method 1,1.454) (Method 2,2.14) (Method 3,4.23)};
\end{axis}
\end{tikzpicture}

\end{document}
10
  • Thank you for your answer :) can I write the values (1.454, 2.14,4.23) on the graph ?
    – Christina
    Oct 5, 2014 at 19:21
  • @Christina See my updated answer. I added only marks because of overlap between the second label and the line. There are probably better ways of dealing with that though. Oct 5, 2014 at 19:26
  • Ah no I mean to write the corresponding values on the drawing curve. Can you do this ?
    – Christina
    Oct 5, 2014 at 19:26
  • @Christina I don't understand what you mean. Do you mean the yticks should be 1.454, 2.14, 4.23 instead of 2,3,4? Oct 5, 2014 at 19:28
  • In fact each point has its own accuracy value. Can we draw the curve and show the accuracy value for each point on the y-axix at the same time in order to make the read of the curve more easy
    – Christina
    Oct 5, 2014 at 19:30
3

Another presentation, as a bar chart, with the pst-bar package:

\documentclass[12pt, pdf, x11names]{article}%
\usepackage{filecontents}
\usepackage{pst-bar}
\newpsbarstyle{mine}{fillstyle=solid, fillcolor=Thistle3!30!,linecolor=Thistle4}

\begin{document}

\sffamily
\begin{pspicture}(-1,-1)(6,5)%
\psset{xunit=3, mathLabel=false}%
\psgrid[gridlabels=0, gridcolor=Thistle3, subgriddiv=0,griddots=30](0,0)(3,5)%
\psaxes[axesstyle=frame, Ox=0, Dx=1, labels=y, ylabelFontSize=\footnotesize, ticks=y, yticksize=-1.5pt 1.5pt, ytickcolor=Thistle3](0,0)(3,5)%
\psset{barcolsep =0.65, labelwidth = 2cm}%
\readpsbardata{\data}{methods.csv}%
\psbarchart[barstyle={mine}]{\data}
\footnotesize
\uput[u](0.5,1.454){1.454}
\uput[u](1.5, 2.14){2.14}
\uput[u](2.5, 4.23){4.23}
\end{pspicture}

\end{document} 

It can be compiled with pdfLaTeX (pdf option for \documentclass) with the switch --shell-escape (TeX Live, MacTeX) or --enable-write18 (MiKTeX).

enter image description here

Methods.csv file:

Method 1, Method 2, Method 3
1.454, 2.14, 4.23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .