![使用 pgfplot 移动 ylabel](https://linux22.com/image/257931/%E4%BD%BF%E7%94%A8%20pgfplot%20%E7%A7%BB%E5%8A%A8%20ylabel.png)
我的 ylabel 与刻度相差太大,我想让它更接近一些。尤其是右图的 ylabel。
\begin{tikzpicture}
\begin{axis}[%
view={0}{90},
width=5.5cm,
height=4.5cm,
scale only axis,
xmin=0, xmax=148,
xlabel={iterations},
ymin=0, ymax=2500,
ylabel={number of infected nodes},
name=plot1,
legend style={at={(0.97,0.03)},anchor=south east,align=left,font=\tiny}]
\addplot [
color=mycolor1,
solid,
line width=0.5pt
]
coordinates{
(0,0)(1,1261)(2,1261)(3,1261)(4,1231)(5,1231)(6,1231)(7,1231)(8,1230)(9,1422)(10,1421)(11,1421)(12,1394)(13,1234)(14,1415)(15,1415)(16,1415)(17,1413)(18,1366)(19,1345)(20,1414)(21,1411)(22,1411)(23,1415)(24,1415)(25,1415)(26,1414)(27,1413)(28,1421)(29,1419)(30,1419)(31,1422)(32,1422)(33,1417)(34,1416)(35,1422)(36,1423)(37,1418)(38,1421)(39,1422)(40,1422)(41,1423)(42,1421)(43,1421)(44,1423)(45,1423)(46,1420)(47,1423)(48,1422)(49,1423)(50,1421)(51,1422)(52,1418)(53,1421)(54,1409)(55,1423)(56,1408)(57,1420)(58,1403)(59,1418)(60,1422)(61,1418)(62,1423)(63,1423)(64,1420)(65,1422)(66,1422)(67,1423)(68,1422)(69,1423)(70,1423)(71,1421)(72,1422)(73,1421)(74,1423)(75,1422)(76,1423)(77,1422)(78,1420)(79,1422)(80,1422)(81,1422)(82,1423)(83,1423)(84,1423)(85,1420)(86,1422)(87,1423)(88,1419)(89,1415)(90,1419)(91,1422)(92,1418)(93,1423)(94,1422)(95,1421)(96,1418)(97,1421)(98,1423)(99,1419)(100,1420)(101,1422)(102,1422)(103,1422)(104,1422)(105,1421)(106,1421)(107,1419)(108,1421)(109,1422)(110,1422)(111,1421)(112,1421)(113,1423)(114,1423)(115,1423)(116,1423)(117,1423)(118,1421)(119,1422)(120,1423)(121,1415)(122,1422)(123,1421)(124,1418)(125,1423)(126,1419)(127,1420)(128,1418)(129,1422)(130,1423)(131,1421)(132,1423)(133,1415)(134,1423)(135,1420)(136,1420)(137,1422)(138,1423)(139,1420)(140,1422)(141,1422)(142,1422)(143,1423)(144,1420)(145,1422)(146,1421)(147,1420)(148,1422)
};
\addlegendentry{lower bound};
\addplot [
color=red,
solid,
line width=0.5pt
]
coordinates{
(0,2318)(1,2317)(2,2317)(3,2317)(4,2312)(5,2310)(6,2309)(7,2308)(8,2307)(9,2309)(10,2306)(11,2306)(12,2304)(13,2297)(14,2232)(15,2226)(16,2217)(17,2212)(18,2248)(19,2240)(20,2175)(21,2191)(22,2190)(23,2179)(24,2173)(25,2152)(26,2121)(27,2120)(28,2143)(29,2150)(30,2071)(31,2091)(32,2023)(33,2006)(34,1957)(35,1959)(36,1955)(37,1892)(38,1943)(39,1910)(40,1901)(41,1861)(42,1856)(43,1886)(44,1890)(45,1869)(46,1916)(47,1838)(48,1801)(49,1865)(50,1833)(51,1829)(52,1861)(53,1808)(54,1812)(55,1889)(56,1806)(57,1800)(58,1780)(59,1776)(60,1780)(61,1813)(62,1801)(63,1728)(64,1755)(65,1754)(66,1795)(67,1685)(68,1682)(69,1734)(70,1721)(71,1831)(72,1698)(73,1658)(74,1612)(75,1692)(76,1680)(77,1633)(78,1622)(79,1692)(80,1594)(81,1702)(82,1663)(83,1616)(84,1655)(85,1769)(86,1655)(87,1704)(88,1668)(89,1705)(90,1563)(91,1578)(92,1587)(93,1608)(94,1603)(95,1581)(96,1617)(97,1502)(98,1661)(99,1665)(100,1740)(101,1588)(102,1541)(103,1571)(104,1599)(105,1533)(106,1559)(107,1619)(108,1582)(109,1533)(110,1641)(111,1502)(112,1535)(113,1594)(114,1577)(115,1595)(116,1539)(117,1658)(118,1614)(119,1466)(120,1552)(121,1580)(122,1498)(123,1589)(124,1602)(125,1586)(126,1460)(127,1505)(128,1438)(129,1485)(130,1458)(131,1625)(132,1476)(133,1458)(134,1460)(135,1433)(136,1475)(137,1547)(138,1463)(139,1475)(140,1444)(141,1428)(142,1505)(143,1484)(144,1468)(145,1451)(146,1621)(147,1489)(148,1422)
};
\addlegendentry{upper bound};
\end{axis}
\begin{axis}[%
view={0}{90},
width=5.5cm,
height=4.5cm,
scale only axis,
xmin=0, xmax=148,
xlabel={iterations},
ymin=0, ymax=70,
ylabel={blocking set size},
at=(plot1.right of south east), anchor=left of south west,
]
\addplot [
color=blue,
solid,
line width=0.5pt,
forget plot
]
coordinates{
(1,0)(2,1)(3,2)(4,3)(5,4)(6,5)(7,7)(8,8)(9,9)(10,10)(11,11)(12,12)(13,13)(14,14)(15,15)(16,16)(17,19)(18,20)(19,21)(20,22)(21,23)(22,23)(23,25)(24,25)(25,26)(26,27)(27,28)(28,29)(29,29)(30,30)(31,30)(32,33)(33,36)(34,35)(35,36)(36,38)(37,39)(38,39)(39,40)(40,41)(41,42)(42,42)(43,42)(44,44)(45,43)(46,45)(47,44)(48,45)(49,47)(50,47)(51,48)(52,46)(53,48)(54,49)(55,50)(56,50)(57,50)(58,52)(59,52)(60,52)(61,53)(62,52)(63,52)(64,52)(65,54)(66,54)(67,55)(68,55)(69,55)(70,57)(71,58)(72,58)(73,59)(74,57)(75,60)(76,58)(77,61)(78,60)(79,60)(80,61)(81,60)(82,61)(83,63)(84,60)(85,60)(86,61)(87,61)(88,61)(89,61)(90,61)(91,62)(92,62)(93,62)(94,62)(95,63)(96,62)(97,64)(98,62)(99,62)(100,65)(101,64)(102,64)(103,62)(104,64)(105,64)(106,64)(107,65)(108,64)(109,63)(110,65)(111,65)(112,66)(113,64)(114,65)(115,66)(116,66)(117,65)(118,65)(119,65)(120,66)(121,67)(122,65)(123,67)(124,65)(125,65)(126,66)(127,66)(128,67)(129,68)(130,68)(131,68)(132,68)(133,68)(134,68)(135,67)(136,68)(137,67)(138,68)(139,67)(140,68)(141,69)(142,68)(143,69)(144,68)(145,68)(146,67)(147,67)(148,67)(149,66)
};
\end{axis}
\end{tikzpicture}%
答案1
您应该使用\pgfplotsset{compat=<your version of PGFPlots>}
,其中您至少需要 PGFPlots 版本 1.3,它将使用新的near ticklabels
锚点激活标签的放置:
\documentclass[]{article}
\usepackage{pgfplots}
\begin{document}
\pgfplotsset{compat=1.6}
\begin{tikzpicture}
\colorlet{mycolor1}{blue}
\begin{axis}[%
view={0}{90},
width=5.5cm,
height=4.5cm,
scale only axis,
xmin=0, xmax=148,
xlabel={iterations},
ymin=0, ymax=2500,
ylabel={number of infected nodes},
name=plot1,
legend style={at={(0.97,0.03)},anchor=south east,align=left,font=\tiny}]
\addplot [
color=mycolor1,
solid,
line width=0.5pt
]
coordinates{
(0,0)(1,1261)(2,1261)(3,1261)(4,1231)(5,1231)(6,1231)(7,1231)(8,1230)(9,1422)(10,1421)(11,1421)(12,1394)(13,1234)(14,1415)(15,1415)(16,1415)(17,1413)(18,1366)(19,1345)(20,1414)(21,1411)(22,1411)(23,1415)(24,1415)(25,1415)(26,1414)(27,1413)(28,1421)(29,1419)(30,1419)(31,1422)(32,1422)(33,1417)(34,1416)(35,1422)(36,1423)(37,1418)(38,1421)(39,1422)(40,1422)(41,1423)(42,1421)(43,1421)(44,1423)(45,1423)(46,1420)(47,1423)(48,1422)(49,1423)(50,1421)(51,1422)(52,1418)(53,1421)(54,1409)(55,1423)(56,1408)(57,1420)(58,1403)(59,1418)(60,1422)(61,1418)(62,1423)(63,1423)(64,1420)(65,1422)(66,1422)(67,1423)(68,1422)(69,1423)(70,1423)(71,1421)(72,1422)(73,1421)(74,1423)(75,1422)(76,1423)(77,1422)(78,1420)(79,1422)(80,1422)(81,1422)(82,1423)(83,1423)(84,1423)(85,1420)(86,1422)(87,1423)(88,1419)(89,1415)(90,1419)(91,1422)(92,1418)(93,1423)(94,1422)(95,1421)(96,1418)(97,1421)(98,1423)(99,1419)(100,1420)(101,1422)(102,1422)(103,1422)(104,1422)(105,1421)(106,1421)(107,1419)(108,1421)(109,1422)(110,1422)(111,1421)(112,1421)(113,1423)(114,1423)(115,1423)(116,1423)(117,1423)(118,1421)(119,1422)(120,1423)(121,1415)(122,1422)(123,1421)(124,1418)(125,1423)(126,1419)(127,1420)(128,1418)(129,1422)(130,1423)(131,1421)(132,1423)(133,1415)(134,1423)(135,1420)(136,1420)(137,1422)(138,1423)(139,1420)(140,1422)(141,1422)(142,1422)(143,1423)(144,1420)(145,1422)(146,1421)(147,1420)(148,1422)
};
\addlegendentry{lower bound};
\addplot [
color=red,
solid,
line width=0.5pt
]
coordinates{
(0,2318)(1,2317)(2,2317)(3,2317)(4,2312)(5,2310)(6,2309)(7,2308)(8,2307)(9,2309)(10,2306)(11,2306)(12,2304)(13,2297)(14,2232)(15,2226)(16,2217)(17,2212)(18,2248)(19,2240)(20,2175)(21,2191)(22,2190)(23,2179)(24,2173)(25,2152)(26,2121)(27,2120)(28,2143)(29,2150)(30,2071)(31,2091)(32,2023)(33,2006)(34,1957)(35,1959)(36,1955)(37,1892)(38,1943)(39,1910)(40,1901)(41,1861)(42,1856)(43,1886)(44,1890)(45,1869)(46,1916)(47,1838)(48,1801)(49,1865)(50,1833)(51,1829)(52,1861)(53,1808)(54,1812)(55,1889)(56,1806)(57,1800)(58,1780)(59,1776)(60,1780)(61,1813)(62,1801)(63,1728)(64,1755)(65,1754)(66,1795)(67,1685)(68,1682)(69,1734)(70,1721)(71,1831)(72,1698)(73,1658)(74,1612)(75,1692)(76,1680)(77,1633)(78,1622)(79,1692)(80,1594)(81,1702)(82,1663)(83,1616)(84,1655)(85,1769)(86,1655)(87,1704)(88,1668)(89,1705)(90,1563)(91,1578)(92,1587)(93,1608)(94,1603)(95,1581)(96,1617)(97,1502)(98,1661)(99,1665)(100,1740)(101,1588)(102,1541)(103,1571)(104,1599)(105,1533)(106,1559)(107,1619)(108,1582)(109,1533)(110,1641)(111,1502)(112,1535)(113,1594)(114,1577)(115,1595)(116,1539)(117,1658)(118,1614)(119,1466)(120,1552)(121,1580)(122,1498)(123,1589)(124,1602)(125,1586)(126,1460)(127,1505)(128,1438)(129,1485)(130,1458)(131,1625)(132,1476)(133,1458)(134,1460)(135,1433)(136,1475)(137,1547)(138,1463)(139,1475)(140,1444)(141,1428)(142,1505)(143,1484)(144,1468)(145,1451)(146,1621)(147,1489)(148,1422)
};
\addlegendentry{upper bound};
\end{axis}
\begin{axis}[%
view={0}{90},
width=5.5cm,
height=4.5cm,
scale only axis,
xmin=0, xmax=148,
xlabel={iterations},
ymin=0, ymax=70,
ylabel={blocking set size},
at=(plot1.right of south east),
xshift=1cm,
anchor=left of south west,
]
\addplot [
color=blue,
solid,
line width=0.5pt,
forget plot
]
coordinates{
(1,0)(2,1)(3,2)(4,3)(5,4)(6,5)(7,7)(8,8)(9,9)(10,10)(11,11)(12,12)(13,13)(14,14)(15,15)(16,16)(17,19)(18,20)(19,21)(20,22)(21,23)(22,23)(23,25)(24,25)(25,26)(26,27)(27,28)(28,29)(29,29)(30,30)(31,30)(32,33)(33,36)(34,35)(35,36)(36,38)(37,39)(38,39)(39,40)(40,41)(41,42)(42,42)(43,42)(44,44)(45,43)(46,45)(47,44)(48,45)(49,47)(50,47)(51,48)(52,46)(53,48)(54,49)(55,50)(56,50)(57,50)(58,52)(59,52)(60,52)(61,53)(62,52)(63,52)(64,52)(65,54)(66,54)(67,55)(68,55)(69,55)(70,57)(71,58)(72,58)(73,59)(74,57)(75,60)(76,58)(77,61)(78,60)(79,60)(80,61)(81,60)(82,61)(83,63)(84,60)(85,60)(86,61)(87,61)(88,61)(89,61)(90,61)(91,62)(92,62)(93,62)(94,62)(95,63)(96,62)(97,64)(98,62)(99,62)(100,65)(101,64)(102,64)(103,62)(104,64)(105,64)(106,64)(107,65)(108,64)(109,63)(110,65)(111,65)(112,66)(113,64)(114,65)(115,66)(116,66)(117,65)(118,65)(119,65)(120,66)(121,67)(122,65)(123,67)(124,65)(125,65)(126,66)(127,66)(128,67)(129,68)(130,68)(131,68)(132,68)(133,68)(134,68)(135,67)(136,68)(137,67)(138,68)(139,67)(140,68)(141,69)(142,68)(143,69)(144,68)(145,68)(146,67)(147,67)(148,67)(149,66)
};
\end{axis}
\end{tikzpicture}%
\end{document}