Advertisement
Guest User

Untitled

a guest
Feb 26th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.84 KB | None | 0 0
  1. newcommand*{plotFileRainbowCertaintyLegendList}[5]{
  2. begin{tikzpicture}
  3. begin{axis}[
  4. %Unboxed,
  5. %Dates,
  6. %twocolumn,
  7. y tick label style={/pgf/number format/fixed},
  8. xlabel={},
  9. legend columns = 3,
  10. legend style={at={(0.5,-0.1)},anchor=north},
  11. #4
  12. ]
  13. %By column number
  14. forcsvlist{listaddLegendList}{50,52,53,56}
  15. %By column name
  16. %forcsvlist{listaddLegendList}{col1Name,col2Name,etc...}
  17.  
  18. pgfplotstableread{#1}Mod
  19. pgfplotstableread{#2}ModLow
  20. pgfplotstableread{#3}ModHigh
  21.  
  22.  
  23. defWaveLow{360}
  24. defWaveHigh{660}
  25.  
  26. pgfplotstablegetcolsof{Mod}
  27. pgfmathtruncatemacronumberofcols{pgfplotsretval-1}
  28. pgfmathsetmacro{waveStep}{(WaveHigh-WaveLow)/numberofcols}
  29.  
  30. pgfplotsinvokeforeach{1,...,numberofcols}{
  31. pgfmathparse{WaveLow+##1*waveStep}
  32. definecolor{Offence##1}{wave}{pgfmathresult}
  33.  
  34. addplot+[Offence##1!50,opacity=0.01,name path=confLow, mark = none, line width = 0, forget plot,#5] table [y index=##1] ModLow ;
  35. addplot+[Offence##1!50,opacity=0.01,name path=confHigh, mark = none, line width = 0, forget plot,#5] table [y index=##1] ModHigh ;
  36. addplot[Offence##1!70,opacity=0.5, forget plot,#5] fill between[of=confLow and confHigh];
  37.  
  38. pgfplotstablegetcolumnnamebyindex{##1}of{Mod}to{colname}
  39. addplot+[Offence##1,solid,thick,mark=none,#5] table [y index=##1] {Mod};
  40. %By column number
  41. xifinlist{##1}{LegendList}{addlegendentryexpanded{colname};}{}
  42. }
  43. %By column name
  44. %xifinlist{colname}{LegendList}{addlegendentryexpanded{colname};}{}
  45. %}
  46. end{axis}
  47. end{tikzpicture}
  48. }
  49.  
  50. % used PGFPlots v1.14
  51. %
  52. % these are just some dummy data files
  53. begin{filecontents*}{low.txt}
  54. x y1 y2 y3 y4 y5 y6 y7 y8 y9
  55. 1 13 23 33 43 53 63 73 83 93
  56. 9 13 23 33 43 53 63 73 83 93
  57. end{filecontents*}
  58. begin{filecontents*}{med.txt}
  59. x y1 y2 y3 y4 y5 y6 y7 y8 y9
  60. 1 15 25 35 45 55 65 75 85 95
  61. 9 15 25 35 45 55 65 75 85 95
  62. end{filecontents*}
  63. begin{filecontents*}{high.txt}
  64. x y1 y2 y3 y4 y5 y6 y7 y8 y9
  65. 1 18 28 38 48 58 68 78 88 98
  66. 9 18 28 38 48 58 68 78 88 98
  67. end{filecontents*}
  68. documentclass[border=5pt]{standalone}
  69. usepackage{pgfplots}
  70. usetikzlibrary{
  71. pgfplots.fillbetween,
  72. }
  73. begin{document}
  74. begin{tikzpicture}
  75. begin{axis}[
  76. no markers,
  77. ]
  78. pgfplotstableread{med.txt}Mod
  79. pgfplotstableread{low.txt}ModLow
  80. pgfplotstableread{high.txt}ModHigh
  81.  
  82. defWaveLow{360}
  83. defWaveHigh{660}
  84. pgfplotstablegetcolsof{Mod}
  85. pgfmathtruncatemacronumberofcols{pgfplotsretval-1}
  86. pgfmathsetmacro{waveStep}{(WaveHigh-WaveLow)/numberofcols}
  87.  
  88. % % this was the old command ...
  89. % pgfplotsinvokeforeach{1,...,numberofcols}{
  90. % ... which is replaced by a list that only contains the column
  91. % numbers for which the legend entry should be shown
  92. pgfplotsinvokeforeach{4,8}{
  93. pgfmathparse{WaveLow+#1*waveStep}
  94. definecolor{Offence#1}{wave}{pgfmathresult}
  95.  
  96. addplot+ [Offence#1!50,opacity=0.01,forget plot,name path=confLow]
  97. table [y index=#1] ModLow;
  98. addplot+ [Offence#1!50,opacity=0.01,forget plot,name path=confHigh]
  99. table [y index=#1] ModHigh;
  100. addplot [Offence#1!70,opacity=0.50,forget plot]
  101. fill between [of=confLow and confHigh];
  102.  
  103. pgfplotstablegetcolumnnamebyindex{#1}of{Mod}to{colname}
  104. addplot+ [Offence#1,solid,thick]
  105. table [y index=#1] {Mod};
  106. addlegendentryexpanded{colname};
  107. }
  108.  
  109. % then provide a second one the previous commands but this time only
  110. % with the elements that should not show up in the legend
  111. % (I hope you get the idea of how to do it with this example)
  112. pgfplotsinvokeforeach{1,...,3,5,6,...,7,numberofcols}{
  113. pgfmathparse{WaveLow+#1*waveStep}
  114. definecolor{Offence#1}{wave}{pgfmathresult}
  115.  
  116. addplot+ [Offence#1!50,opacity=0.01,forget plot,name path=confLow]
  117. table [y index=#1] ModLow;
  118. addplot+ [Offence#1!50,opacity=0.01,forget plot,name path=confHigh]
  119. table [y index=#1] ModHigh;
  120. addplot [Offence#1!70,opacity=0.50,forget plot]
  121. fill between [of=confLow and confHigh];
  122.  
  123. pgfplotstablegetcolumnnamebyindex{#1}of{Mod}to{colname}
  124. addplot+ [Offence#1,solid,thick]
  125. table [y index=#1] {Mod};
  126. % % and of course this time don't provide the legend command
  127. % addlegendentryexpanded{colname};
  128. }
  129. end{axis}
  130. end{tikzpicture}
  131. end{document}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement