我正在尝试绘制一些数据,其中 X 轴以字节为单位。值呈指数增长,因此我手动缩放它们以获得更好的图表。但是,我不想显示日志,而是显示实数,并且我想显示具有可变单位(字节、Kb、Mb)的数字。我很接近,但我缺少单位。
\documentclass{paper}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[pdftex]{color}
\usepackage{balance}
\usepackage{lmodern}
\usepackage{tikz}
\usetikzlibrary{arrows,shadows,patterns}
\usepackage{pgf-umlsd}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\usepackage{amsmath}
\usepackage{subcaption}
\usepackage{dblfloatfix}
\usepackage{listings}
\usepackage{color}
\pgfplotstableread{
{Data Size} {Shared Memory} {NIO}
0 1.510618995 1.211303577
1 3.2303486 2.284973183
1.5849625007 4.856564878 3.650475913
2 6.477938316 4.413739735
2.5849625007 9.712070412 7.308872177
3 12.931555487 8.820402778
3.5849625007 19.484353638 12.822872274
3.7004397181 21.122457882 14.851562274
4 25.912743129 18.621127822
4.2479275134 30.729567163 22.179711705
4.3923174228 34.29160211 19.027447421
4.5849625007 38.244025295 29.328904007
4.7548875022 43.959939412 32.568470093
4.8579809951 46.929519191 34.986339417
5 52.492719706 39.106509783
5.1292830169 58.46781981 31.501307665
5.4918530963 73.543666985 43.323522934
5.5849625007 77.459322667 48.490743999
5.672425342 82.985235817 56.872079534
5.9307373376 99.796973815 54.818062952
6 102.283900308 57.550038602
6.0660891905 108.375577493 60.505008949
6.5391588111 148.767633673 83.800438008
6.5849625007 152.995602336 106.139907555
6.6293566201 160.628615581 89.067641012
6.9657842847 200.161297725 112.453472776
7 205.824015933 135.930753075
7.0334230015 210.192513373 116.697242107
7.5622424242 304.035778887 168.699330324
7.5849625007 305.748875502 178.617329882
7.6073303137 314.050317173 223.004631634
7.9829935747 401.791173697 304.945579899
8 409.483432748 303.157529871
8.0168082877 424.119265186 231.545405236
8.5736471875 605.448555176 424.80696054
8.5849625007 607.284603452 342.123641214
8.5961897561 615.863754668 395.555755955
8.9915218461 803.207926285 611.575583119
9 812.506013352 553.18025024
9.0084286221 815.09008592 578.762145252
9.5793159376 1210.628898233 925.793618042
9.5849625007 1209.223171089 683.90157147
9.5905870499 1219.631198049 893.794979677
9.9957671509 1596.264405994 1103.914749616
10 1606.587640249 1085.280140642
10.0042204663 1616.864825222 1130.343164423
10.5821419817 2345.139190349 1528.461298638
10.5849625007 2403.540379252 1430.78942209
10.5877775163 2366.704676255 1456.155914263
10.9978851278 3076.509079427 1803.067395975
11 3078.925940461 1746.102644706
11.0021117765 3111.258074768 1994.433990999
11.5835529305 4556.56852076 3058.174009469
11.5849625007 4502.975871005 2551.424401063
11.5863706951 4538.094725282 2533.045417625
11.9989429514 5827.952659919 4983.721139081
12 5812.588729177 3774.507385952
12.0010562746 5853.675269234 4017.979668263
12.5842578877 8386.555402598 4910.603339731
12.5849625007 8332.804968689 4966.990490482
12.5856667697 8392.878076465 5048.779860844
12.9994715725 10541.499375969 9471.012935496
13 10529.066751163 6233.173950593
13.000528234 10583.146089496 7356.552861198
13.5846102372 14401.37205005 8704.617585743
13.5849625007 14363.974258746 8713.01377627
13.5853146782 14282.311931098 10376.784988679
13.9997358105 17924.32579547 10960.299110444
14 18539.802353817 10978.068437467
14.0002641412 17573.649107848 12459.412789012
14.5847863797 22813.544369689 18111.530868468
14.5849625007 23197.178627511 15523.929346838
14.5851386002 24072.748522204 14975.096833361
14.9998679113 27122.227913974 22139.146166433
15 28343.29998547 20174.984879434
15.0001320766 27102.259759124 22299.988561706
15.5848744429 33093.457918842 24583.590207991
15.5849625007 37503.657556209 24067.295665602
15.5850505532 35029.522698607 21385.294903538
15.9999339572 35965.052986014 22156.773973963
16 36280.521720143 22768.653369153
16.0000660398 35824.858992535 22095.615170307
16.5849184725 39663.885952713 31544.055792361
16.5849625007 39702.343473768 32020.413157657
16.5850065276 39648.969347573 28171.132563909
16.999966979 39892.031287074 29686.823448866
17 39989.357985912 29563.339750158
17.0000330203 39881.838316571 29597.736848209
17.5849404868 39775.794203249 31879.906514408
17.5849625007 40090.939326761 42632.564123951
17.5849845143 39931.689963714 31764.349460218
17.9999834896 42059.054279617 33266.028653703
18 42036.328865752 33289.438190973
18.0000165102 41612.020018579 33235.604391119
18.5849514938 43934.287383115 34805.978837333
18.5849625007 43757.423406646 34775.082842428
18.5849735076 43806.569286575 34868.32660189
18.9999917448 41188.289875588 35271.795693727
19 41493.55703896 34852.366230723
19.0000082551 41261.894071401 34783.859418754
19.5849569973 46750.487759933 34134.247276319
19.5849625007 46742.858105665 34030.893356802
19.5849680042 46272.488727414 34022.599544173
19.9999958724 39361.483527363 32070.098342443
20 39011.235342666 32078.172520878
20.0000041276 39417.359046151 38439.343773152
20.584959749 32541.918497241 33797.506118382
20.5849625007 32994.871611205 33265.916556813
20.5849652524 33282.976976094 33338.510640811
20.9999979362 30617.072384717 36638.090297614
21 30363.559637657 30035.390170359
21.0000020638 30904.87103504 36802.61117229
21.5849611249 32602.98950649 29047.077888273
21.5849625007 32565.912266974 27241.537806327
21.5849638766 32245.756882312 25122.081310011
21.9999989681 34631.731967715 29207.946376923
22 34818.087121474 26740.547005968
22.0000010319 34592.778882135 23472.260927074
22.5849618128 36725.131366442 24061.012240664
22.5849625007 37169.700021537 24183.159975874
22.5849631887 36395.704815157 25024.525623474
22.9999994841 38375.918718521 26704.848945865
23 37520.785869843 31543.462669175
23.0000005159 38196.313421571 24765.815374737
23.5849621568 39862.547608764 24697.332265871
23.5849625007 39566.218535168 24819.606183673
23.5849628447 40324.827504458 24693.315933731
23.999999742 40827.102556167 25069.671590142
24 40424.324710132 30577.659465717
24.000000258 40358.89294868 24941.099097069
24.5849623287 41435.360383826 31862.436201921
24.5849625007 40956.508539929 28507.061514714
24.5849626727 41644.67545765 27605.865978166
24.999999871 42239.781170468 26207.879591305
25 41752.769862369 25473.326348502
25.000000129 41613.905092199 25261.482217836
25.5849624147 42649.518306265 30801.895171737
25.5849625007 42414.091666634 25250.400756266
25.5849625867 43194.093893614 25250.152249501
25.9999999355 42879.187112688 25235.946710162
26 44507.168450242 25306.504292221
26.0000000645 43992.340356826 25344.246828366
}\datatable
\begin{document}
\begin{tikzpicture}
\begin{axis}[
width= 1\columnwidth,
height=4cm,
xlabel={Message Size},
ylabel={Gbps},
%y label style={pos=east},
y label style={at={(0.1, 0.5)}},
x label style={at={(0.5, 0.08)}},
legend pos=north west,
legend style={anchor=north west,font=\tiny},
xtick={0,2,4,6,8,10,12,14,16,18,20,22,24,26},
%xmode=log,
%log basis x={2},
scaled y ticks = false,
y tick label style={
/pgf/number format/1000 sep = \thinspace
},
x tick label style={font=\tiny},
scaled x ticks=manual:{}{%
\pgfmathparse{ (#1 < 10) ? pow(2,#1) : ((#1 < 20) ? pow(2, #1 - 10):pow(2, #1 - 20))}%
},
xticklabel={\pgfmathprintnumber\tick },
scaled y ticks=manual:{}{%
\pgfmathparse{#1/1000}%
},
yticklabel={\pgfmathprintnumber\tick},
]
\addplot [mark=+,color=black] table[y={Shared Memory}, x = {Data Size}] {\datatable};
\addlegendentry{Shared Memory}[minimum height=1.9in];
\addplot [mark=none,color=gray] table[y={NIO}, x ={Data Size}] {\datatable};
\addlegendentry{NIO}[minimum height=1.9in];
\end{axis}
\end{tikzpicture}
\end{document}
结果是: 但是,我想在 x 轴上进行小幅修改。而不是
{1,4,16,64,256,1,4,16,64,256,1,4,16,64}
我想要 {1,4,16,64,256,1Kb,4Kb,16Kb,64Kb,256Kb,1Mb,4Mb,16Mb,64Mb}
答案1
我会设置xticklabels
显式并旋转它们。我认为最好对所有都使用相同的尺寸ticklabels
。
\documentclass{paper}
\usepackage{lmodern}
\usepackage{pgfplots}
\pgfplotsset{compat=1.10}
\pgfplotstableread{
{Data Size} {Shared Memory} {NIO}
...
}\datatable
\begin{document}
\centering
\begin{tikzpicture}
\begin{axis}[
width=\columnwidth,
height=4cm,
legend pos=north west,
legend style={anchor=north west,font=\scriptsize},
%
tick label style={font=\scriptsize},
%
xlabel={Message Size},
xtick={0,2,...,26},
x tick label style={rotate=90},
xticklabels={
1\,b,4\,b,16\,b,64\,b,256\,b,
1\,Kb,4\,Kb,16\,Kb,64\,Kb,256\,Kb,
1\,Mb,4\,Mb,16\,Mb,64\,Mb
},
%
ylabel={Gbps},
scaled y ticks=manual:{}{\pgfmathparse{#1/1000}},
]
\addplot [mark=+,color=black] table[y={Shared Memory}, x = {Data Size}] {\datatable};
\addlegendentry{Shared Memory}[minimum height=1.9in];
\addplot [mark=none,color=gray] table[y={NIO}, x ={Data Size}] {\datatable};
\addlegendentry{NIO}[minimum height=1.9in];
\end{axis}
\end{tikzpicture}
\end{document}
答案2
已修订,使用 OP 提供的完整 MWE。我所做的就是在我认为有意义的地方添加符号。我将这些符号添加为 x 标签的一部分。我认为在数字下方标注比在数字本身标注看起来更好。
如果您更改图表的比例,则尺寸\cyclewidth
也\loffset
需要修改。
注意:我改变了绘图宽度以更好地符合您的图片。
\documentclass{paper}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[pdftex]{color}
\usepackage{balance}
\usepackage{lmodern}
\usepackage{tikz}
\usetikzlibrary{arrows,shadows,patterns}
\usepackage{pgf-umlsd}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\usepackage{amsmath}
\usepackage{subcaption}
\usepackage{dblfloatfix}
\usepackage{listings}
\usepackage{color}
\usepackage{stackengine}
\pgfplotstableread{
{Data Size} {Shared Memory} {NIO}
0 1.510618995 1.211303577
1 3.2303486 2.284973183
1.5849625007 4.856564878 3.650475913
2 6.477938316 4.413739735
2.5849625007 9.712070412 7.308872177
3 12.931555487 8.820402778
3.5849625007 19.484353638 12.822872274
3.7004397181 21.122457882 14.851562274
4 25.912743129 18.621127822
4.2479275134 30.729567163 22.179711705
4.3923174228 34.29160211 19.027447421
4.5849625007 38.244025295 29.328904007
4.7548875022 43.959939412 32.568470093
4.8579809951 46.929519191 34.986339417
5 52.492719706 39.106509783
5.1292830169 58.46781981 31.501307665
5.4918530963 73.543666985 43.323522934
5.5849625007 77.459322667 48.490743999
5.672425342 82.985235817 56.872079534
5.9307373376 99.796973815 54.818062952
6 102.283900308 57.550038602
6.0660891905 108.375577493 60.505008949
6.5391588111 148.767633673 83.800438008
6.5849625007 152.995602336 106.139907555
6.6293566201 160.628615581 89.067641012
6.9657842847 200.161297725 112.453472776
7 205.824015933 135.930753075
7.0334230015 210.192513373 116.697242107
7.5622424242 304.035778887 168.699330324
7.5849625007 305.748875502 178.617329882
7.6073303137 314.050317173 223.004631634
7.9829935747 401.791173697 304.945579899
8 409.483432748 303.157529871
8.0168082877 424.119265186 231.545405236
8.5736471875 605.448555176 424.80696054
8.5849625007 607.284603452 342.123641214
8.5961897561 615.863754668 395.555755955
8.9915218461 803.207926285 611.575583119
9 812.506013352 553.18025024
9.0084286221 815.09008592 578.762145252
9.5793159376 1210.628898233 925.793618042
9.5849625007 1209.223171089 683.90157147
9.5905870499 1219.631198049 893.794979677
9.9957671509 1596.264405994 1103.914749616
10 1606.587640249 1085.280140642
10.0042204663 1616.864825222 1130.343164423
10.5821419817 2345.139190349 1528.461298638
10.5849625007 2403.540379252 1430.78942209
10.5877775163 2366.704676255 1456.155914263
10.9978851278 3076.509079427 1803.067395975
11 3078.925940461 1746.102644706
11.0021117765 3111.258074768 1994.433990999
11.5835529305 4556.56852076 3058.174009469
11.5849625007 4502.975871005 2551.424401063
11.5863706951 4538.094725282 2533.045417625
11.9989429514 5827.952659919 4983.721139081
12 5812.588729177 3774.507385952
12.0010562746 5853.675269234 4017.979668263
12.5842578877 8386.555402598 4910.603339731
12.5849625007 8332.804968689 4966.990490482
12.5856667697 8392.878076465 5048.779860844
12.9994715725 10541.499375969 9471.012935496
13 10529.066751163 6233.173950593
13.000528234 10583.146089496 7356.552861198
13.5846102372 14401.37205005 8704.617585743
13.5849625007 14363.974258746 8713.01377627
13.5853146782 14282.311931098 10376.784988679
13.9997358105 17924.32579547 10960.299110444
14 18539.802353817 10978.068437467
14.0002641412 17573.649107848 12459.412789012
14.5847863797 22813.544369689 18111.530868468
14.5849625007 23197.178627511 15523.929346838
14.5851386002 24072.748522204 14975.096833361
14.9998679113 27122.227913974 22139.146166433
15 28343.29998547 20174.984879434
15.0001320766 27102.259759124 22299.988561706
15.5848744429 33093.457918842 24583.590207991
15.5849625007 37503.657556209 24067.295665602
15.5850505532 35029.522698607 21385.294903538
15.9999339572 35965.052986014 22156.773973963
16 36280.521720143 22768.653369153
16.0000660398 35824.858992535 22095.615170307
16.5849184725 39663.885952713 31544.055792361
16.5849625007 39702.343473768 32020.413157657
16.5850065276 39648.969347573 28171.132563909
16.999966979 39892.031287074 29686.823448866
17 39989.357985912 29563.339750158
17.0000330203 39881.838316571 29597.736848209
17.5849404868 39775.794203249 31879.906514408
17.5849625007 40090.939326761 42632.564123951
17.5849845143 39931.689963714 31764.349460218
17.9999834896 42059.054279617 33266.028653703
18 42036.328865752 33289.438190973
18.0000165102 41612.020018579 33235.604391119
18.5849514938 43934.287383115 34805.978837333
18.5849625007 43757.423406646 34775.082842428
18.5849735076 43806.569286575 34868.32660189
18.9999917448 41188.289875588 35271.795693727
19 41493.55703896 34852.366230723
19.0000082551 41261.894071401 34783.859418754
19.5849569973 46750.487759933 34134.247276319
19.5849625007 46742.858105665 34030.893356802
19.5849680042 46272.488727414 34022.599544173
19.9999958724 39361.483527363 32070.098342443
20 39011.235342666 32078.172520878
20.0000041276 39417.359046151 38439.343773152
20.584959749 32541.918497241 33797.506118382
20.5849625007 32994.871611205 33265.916556813
20.5849652524 33282.976976094 33338.510640811
20.9999979362 30617.072384717 36638.090297614
21 30363.559637657 30035.390170359
21.0000020638 30904.87103504 36802.61117229
21.5849611249 32602.98950649 29047.077888273
21.5849625007 32565.912266974 27241.537806327
21.5849638766 32245.756882312 25122.081310011
21.9999989681 34631.731967715 29207.946376923
22 34818.087121474 26740.547005968
22.0000010319 34592.778882135 23472.260927074
22.5849618128 36725.131366442 24061.012240664
22.5849625007 37169.700021537 24183.159975874
22.5849631887 36395.704815157 25024.525623474
22.9999994841 38375.918718521 26704.848945865
23 37520.785869843 31543.462669175
23.0000005159 38196.313421571 24765.815374737
23.5849621568 39862.547608764 24697.332265871
23.5849625007 39566.218535168 24819.606183673
23.5849628447 40324.827504458 24693.315933731
23.999999742 40827.102556167 25069.671590142
24 40424.324710132 30577.659465717
24.000000258 40358.89294868 24941.099097069
24.5849623287 41435.360383826 31862.436201921
24.5849625007 40956.508539929 28507.061514714
24.5849626727 41644.67545765 27605.865978166
24.999999871 42239.781170468 26207.879591305
25 41752.769862369 25473.326348502
25.000000129 41613.905092199 25261.482217836
25.5849624147 42649.518306265 30801.895171737
25.5849625007 42414.091666634 25250.400756266
25.5849625867 43194.093893614 25250.152249501
25.9999999355 42879.187112688 25235.946710162
26 44507.168450242 25306.504292221
26.0000000645 43992.340356826 25344.246828366
}\datatable
\def\cyclewidth{1.82cm}
\def\loffset{0.6cm}
\begin{document}
{\centering
\begin{tikzpicture}
\begin{axis}[
width= .6\columnwidth,
height=4cm,
xlabel={\stackon[6pt]{Message Size}
{\tiny\sffamily\hspace{\loffset}\smash{\rule{.4pt}{3ex}}%
\makebox[\cyclewidth]{bytes}\smash{\rule{.4pt}{3ex}}%
\makebox[\cyclewidth]{kb}\smash{\rule{.4pt}{3ex}}%
\makebox[\cyclewidth]{Mb}}},
ylabel={Gbps},
%y label style={pos=east},
y label style={at={(0.1, 0.5)}},
x label style={at={(0.5, 0.08)}},
legend pos=north west,
legend style={anchor=north west,font=\tiny},
xtick={0,2,4,6,8,10,12,14,16,18,20,22,24,26},
%xmode=log,
%log basis x={2},
scaled y ticks = false,
y tick label style={
/pgf/number format/1000 sep = \thinspace
},
x tick label style={font=\tiny},
scaled x ticks=manual:{}{%
\pgfmathparse{ (#1 < 10) ? pow(2,#1) : ((#1 < 20) ? pow(2, #1 - 10):pow(2, #1 - 20))}%
},
xticklabel={\pgfmathprintnumber\tick },
scaled y ticks=manual:{}{%
\pgfmathparse{#1/1000}%
},
yticklabel={\pgfmathprintnumber\tick},
]
\addplot [mark=+,color=black] table[y={Shared Memory}, x = {Data Size}] {\datatable};
\addlegendentry{Shared Memory}[minimum height=1.9in];
\addplot [mark=none,color=gray] table[y={NIO}, x ={Data Size}] {\datatable};
\addlegendentry{NIO}[minimum height=1.9in];
\end{axis}
\end{tikzpicture}\par}
\end{document}