LaTeX forum ⇒ Graphics, Figures & TablesSymbolic axis values - strange sequence

Information and discussion about graphics, figures & tables in LaTeX documents.
Gennaro90
Posts: 1
Joined: Sun Nov 05, 2017 8:40 pm

Symbolic axis values - strange sequence

Postby Gennaro90 » Sun Nov 05, 2017 8:46 pm

Hello everyone, I tried to get symbolic values x1, x2, x3, x4 on x axis and C(x1),...,C(x4) on y axis.

  1. \begin{tikzpicture}
  2. \begin{axis}[
  3. xlabel={$x$},
  4. ylabel={$y$},
  5. axis lines=center,
  6. symbolic x coords={$x_1$, $x_2$, $x_3$, $x_4$, $x_5$},
  7. symbolic y coords={$C(x_1)$, $C(x_2)$, $C(x_3),
  8. $C(x_4)$, $C(x_5)$}]
  9. \end{axis}
  10. \end{tikzpicture}


but the result is not right because x1 and C(x1) occur on 2 ticks, x2 and C(x2) on 3 ticks. How can I get the right plot?

Thank you very much for your time.

Tags:

User avatar
Stefan Kottwitz
Site Admin
Posts: 8534
Joined: Mon Mar 10, 2008 9:44 pm
Location: Hamburg, Germany
Contact:

Postby Stefan Kottwitz » Mon Nov 06, 2017 5:30 pm

Hi Gennaro,

welcome to the forum!

With symbolic coordinates, a question may be, what is the x range, the y range, the placement. It may be undefined here, what may explain that labels are randomly chosen. Interesting anyway. What is missing though, is ytick=data and ytick=data.

But here is a working solution for you. I take normal coordinates, but symbolic labels, that gives a good picture and using these coordinates you can eve choose fine positions for labels or between symbolic values.

  1. \documentclass[border=10pt]{standalone}
  2. \usepackage{pgfplots}
  3. \begin{document}
  4. \begin{tikzpicture}
  5. \begin{axis}[
  6. xlabel = {$x$},
  7. ylabel = {$y$},
  8. xmin = 0,
  9. xmax = 5.5,
  10. ymin = 0,
  11. ymax = 5.5,
  12. domain = -1:5
  13. y domain = -1:5,
  14. axis lines = center,
  15. xtick = { 1,2,3,4,5 },
  16. ytick = { 1,2,3,4,5 },
  17. xticklabels = { $x_1$, $x_2$, $x_3$, $x_4$, $x_5$ },
  18. yticklabels = { $C(x_1)$, $C(x_2)$, $C(x_3)$,
  19. $C(x_4)$, $C(x_5)$ }
  20. ]
  21. \end{axis}
  22. \end{tikzpicture}
  23. \end{document}


plot.png
plot.png (11.31 KiB) Viewed 93 times


Stefan
Site admin

esdd
Posts: 34
Joined: Sat Jan 25, 2014 9:13 pm
Location: Germany

Postby esdd » Tue Nov 07, 2017 11:54 am



Return to “Graphics, Figures & Tables”

Who is online

Users browsing this forum: No registered users and 6 guests