SHARE
TWEET

Untitled

a guest Aug 18th, 2019 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. documentclass{minimal}
  2. usepackage{pgfplots}
  3. usepgfplotslibrary{dateplot}
  4.  
  5. begin{document}
  6. begin{tikzpicture}
  7.  
  8.   begin{axis}[
  9.     date coordinates in=x,
  10.     xtick=data,
  11.     xticklabel={hour:minute:second},
  12.     scaled x ticks=false,
  13.     xticklabel style={anchor=east,rotate=45},
  14.     xticklabels={13:00:30,
  15.       13:00:40,
  16.       13:00:50}
  17.     ]
  18.     addplot table [col sep=comma,trim cells=true,y=value1,scatter,only marks] {data.csv};
  19.   end{axis}
  20.  
  21. end{tikzpicture}
  22. end{document}
  23.      
  24. date,                   value1
  25. 2013-06-03 13:00:00,       2
  26. 2013-06-03 13:00:15,       3
  27. 2013-06-03 13:00:50,       14
  28.      
  29. documentclass{standalone}
  30. usepackage{pgfplots}
  31. usepgfplotslibrary{dateplot}
  32.  
  33. defcheckSameDate#1{%
  34.     ifnumcoordindex=0
  35.         gdefitsDate{#1}%
  36.     else
  37.         deftemp{#1}%
  38.         ifxtempitsDate
  39.         else
  40.             PackageError{custom}{Sorry, expected the same date but got two different ones itsDatespace and #1}{}%
  41.         fi
  42.     fi
  43. }%
  44.  
  45. defensuretwodigits#1{%
  46.     ifnum#1<10
  47.         edefpgfmathresult{0#1}%
  48.     else
  49.         edefpgfmathresult{#1}%
  50.     fi
  51. }%
  52.  
  53. pgfplotsset{
  54.     % invoked with
  55.     % 2013-06-03 23:59:00
  56.     % ->
  57.     %  #1 = 2013
  58.     %  #2 = 06
  59.     %  #3 = 03
  60.     %  #4 = 23
  61.     %  #5 = 59
  62.     %  #6 = 00
  63.     @datetime to number/.code args={#1-#2-#3 #4:#5:#6}{%
  64.         checkSameDate{#1-#2-#3}%
  65.         %
  66.         % convert to full seconds:
  67.         pgfmathparse{#4*3600+60*#5 + #6}%
  68.     },
  69.     %
  70.     % This is a style which activates the new feature:
  71.     date same day in x/.style={%
  72.         x coord trafo/.style={/pgfplots/@datetime to number=##1},
  73.         scaled x ticks=false,
  74.         plot coordinates/math parser=false,
  75.         %
  76.         % the following keys are ONLY here to format tick labels
  77.         x coord inv trafo/.code={%
  78.             begingroup
  79.             % compute the value
  80.             pgfkeys{/pgf/fpu}%
  81.             %
  82.             % ... seconds
  83.             pgfmathparse{mod(##1,60)}%
  84.             pgfmathfloattoint{pgfmathresult}%
  85.             ensuretwodigits{pgfmathresult}%
  86.             globalletseconds=pgfmathresult
  87.             %
  88.             % ... minutes
  89.             pgfmathparse{mod( (##1 - seconds)/60,60)}%
  90.             pgfmathfloattoint{pgfmathresult}%
  91.             ensuretwodigits{pgfmathresult}%
  92.             globalletminutes=pgfmathresult
  93.             %
  94.             % ... hours
  95.             pgfmathparse{(##1 - 60*minutes - seconds)/3600}%
  96.             pgfmathfloattoint{pgfmathresult}%
  97.             ensuretwodigits{pgfmathresult}%
  98.             globallethours=pgfmathresult
  99.             endgroup
  100.         },
  101.         xticklabel style={
  102.             /pgf/number format/fixed,
  103.         },
  104.         xticklabel=hours:minutes:seconds,
  105.     },
  106. }
  107.  
  108. begin{document}
  109. begin{tikzpicture}
  110.   begin{axis}[
  111.     %xtick=data,
  112.     xticklabel style={anchor=east,rotate=45},
  113.     date same day in x,
  114.     ]
  115.     addplot table [col sep=comma,trim cells=true,y=value1,scatter,only marks] {
  116. date,                   value1
  117. 2013-06-03 23:59:00,       2
  118. 2013-06-03 23:59:10,       3
  119. 2013-06-03 23:59:20,       3
  120. 2013-06-03 23:59:30,       3
  121. 2013-06-03 23:59:40,      3
  122. 2013-06-03 23:59:50,       14
  123. 2013-06-03 23:59:59,       14
  124. };
  125.   end{axis}
  126.  
  127. end{tikzpicture}
  128. end{document}
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top