0

With the code

\begin{tikzpicture}[scale=0.8]
\begin{axis}[colormap/blackwhite,legend style ={ at={(1.03,1)}, 
    anchor=north west, draw=black, 
    fill=white,align=left},
cycle list name=black white,
smooth]
\addplot coordinates{(1,0.895975056689342) (2,0.88858024691358) (3,0.845842956120092) (4,0.939493433395872) (5,0.876114081996435) (6,0.855309218203034) (7,0.85309649543927) (8,0.894003868471954) (9,0.857021996615905) (10,0.842038753159225) (11,0.89045719545873) (12,0.839759462327556) (13,0.794553464156988) (14,0.800123762376238)};
\end{axis}
\end{tikzpicture}

I can plot e.g. an experimental curve. I would like to replace x-values with couples like, e.g. (5,95) instead 1, (6,94) instead 2 and so on. Like this:

enter image description here

3
  • 1
    I honestly don't understand what you mean, could you try to clarify? Apr 19, 2020 at 16:23
  • 1
    Possibly symbolic x coordinates is what you need. Apr 19, 2020 at 16:27
  • I updated the post. Thank you.
    – Mark
    Apr 19, 2020 at 17:39

1 Answer 1

2

The naive attempt with symbolic x coords didn't work, but you can do this by specifying the xtick and xticklabels manually. xtick can take a list of numbers, something like {1,...,5} which gives integers from 1 to 5, or the keyword data (i.e. xtick=data) which will place a tick for each datapoint in the first \addplot.

xticklabels takes a comma separated list of text to use for the ticklabels. In your case you need to wrap each ticklabel in {}, because there is a comma in them. See a complete example below.

enter image description here

\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
  colormap/blackwhite,
  legend style = {
    at={(1.03,1)}, 
    anchor=north west,
    align=left
  },
  cycle list name=black white,
  smooth,
  xtick={1,5,9},
  xticklabels={{(1,3.13)},{(2,42)},{(3,1.618)}}
  ]

\addplot coordinates{(1,0.895975056689342) (2,0.88858024691358) (3,0.845842956120092) (4,0.939493433395872) (5,0.876114081996435) (6,0.855309218203034) (7,0.85309649543927) (8,0.894003868471954) (9,0.857021996615905) (10,0.842038753159225) (11,0.89045719545873) (12,0.839759462327556) (13,0.794553464156988) (14,0.800123762376238)};

\end{axis}
\end{tikzpicture}
\end{document}
1
  • [xtick=data] will do some of the work, but you will still need manual xticklalels. Apr 20, 2020 at 3:42

You must log in to answer this question.

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