LaTeX forum ⇒ Graphics, Figures & Tablespgfplots graph labels (year/month)

Information and discussion about graphics, figures & tables in LaTeX documents.
m1l05z
Posts: 1
Joined: Wed Sep 23, 2015 11:10 pm

pgfplots graph labels (year/month)

Postby m1l05z » Wed Sep 23, 2015 11:24 pm

Hi,
I am trying to use a graph in pgfplots of this example: http://tex.stackexchange.com/questions/120336/adding-several-labels-year-month-to-a-graph-in-pgfplots @Jake's answer, I added my data but my graph looks strange:

Image
Here is my graph's code:
  1. \usepackage{pgfplots}
  2. \usepgfplotslibrary{dateplot}
  3. \usetikzlibrary{calc}
  4. \makeatletter
  5. \long\def\ifnodedefined#1#2#3{%
  6. \@ifundefined{pgf@sh@ns@#1}{#3}{#2}%
  7. }
  8. \makeatother
  9. \begin{tikzpicture}
  10. \begin{axis}[
  11. date coordinates in=x,
  12. xtick=data,
  13. tick pos=left,
  14. yticklabel style={append after command={(\tikzlastnode.east) edge +(0.15cm,0)}},
  15. major tick length=0pt,
  16. extra x ticks={2013-10-01,2014-06-01, 2015-07-01},
  17. extra x tick style={
  18. yshift=-3.5ex,
  19. xticklabel=\year,
  20. xticklabel style={name={}},
  21. every x tick label/.style={}
  22. },
  23. xticklabel style={
  24. anchor=near xticklabel,
  25. alias=tick\ticknum,
  26. name=\ifnodedefined{start\year} % Have we already started this year?
  27. {end\year} % Then this could be the last month
  28. {start\year}, % Otherwise, start the year
  29. append after command=
  30. \pgfextra{\pgfmathtruncatemacro\lastyear{\year-1}}
  31. \ifnodedefined{end\lastyear}
  32. {
  33. {\ifnum\month=1 ({$(end\lastyear.south west)!0.7!(start\year.south east)$}|-{rel axis cs:0,0}) edge ++(0,-7ex)
  34. \fi}
  35. }
  36. {}
  37. \ifnum\ticknum>0
  38. \ifnum\month>1
  39. \pgfextra{\pgfmathtruncatemacro\prevticknum{\ticknum-1}}
  40. ($(tick\prevticknum.north east)!0.5!(tick\ticknum.north west)$) edge ++({0,-3ex})
  41. \fi
  42. \fi
  43. },
  44. after end axis/.code={
  45. \draw (rel axis cs:0,0) -- ++(0,-7ex)
  46. (rel axis cs:1,0) -- ++(0,-7ex);
  47. },
  48. xticklabel=\month,
  49. date ZERO=2013-08-01,% <- improves precision!
  50. ]
  51. \addplot coordinates {
  52. (2013-08-01, 215329)
  53. (2013-10-01, 225632)
  54. (2013-12-01, 229746)
  55. (2014-01-01, 231838)
  56. (2014-03-01, 233103)
  57. (2014-04-01, 236439)
  58. (2014-06-01, 240507)
  59. (2014-07-01, 259075)
  60. (2014-09-01, 269991)
  61. (2014-11-01, 268667)
  62. (2014-12-01, 267881)
  63. (2015-02-01, 276134)
  64. (2015-03-01, 294944)
  65. (2015-05-01, 297439)
  66. (2015-07-01, 297291)
  67. (2015-08-01, 286560)
  68. (2015-09-01, 280206)
  69. };
  70. \end{axis}
  71. \end{tikzpicture}


I will be grateful of any sugestions :)

Tags:

Return to “Graphics, Figures & Tables”

Who is online

Users browsing this forum: Bing [Bot] and 9 guests