我的代码
\documentclass{article}
\usepackage{pgfplots}
\usepackage{filecontents}
\begin{filecontents}{filename.csv}
Month, Year, Host-Count
Jul, 1993, 1776000
Jul, 1994, 3212000
Jul, 1995, 6642000
Jul, 1996, 12881000
Jul, 1997, 19540000
Jul, 1998, 36739000
Jul, 1999, 56218000
Jul, 2000, 93047785
Jul, 2001, 125888197
Jul, 2002, 162128493
Jan, 2003, 171638297
Jul, 2004, 285139107
Jul, 2005, 353284187
Jul, 2006, 439286364
Jul, 2007, 489774269
Jul, 2008, 570937778
Jul, 2009, 681064561
Jul, 2010, 768913036
Jul, 2011, 849869781
Jul, 2012, 908585739
Jul, 2013, 996230757
Jul, 2014, 1028544414
Jul, 2015, 1033836245
Jan, 2016, 1048766623
Jul, 2017, 1074971748
\end{filecontents}
\begin{document}
\begin{figure}[h]
\centering
\resizebox{0.76\linewidth}{!}{
% \pgfplotstableread[col sep=comma]{Figures/HostsIncreaseICS.csv}\datatable
\begin{tikzpicture}
\begin{axis}[
%------------X-Axis data and style---------------
enlarge x limits=.01,
xlabel={Year},
xlabel near ticks,
xticklabel style={rotate=90,anchor=east},
xtick=data,
x tick label style={/pgf/number format/1000 sep ={} },
%------------X-Axis data and style---------------
ytick=data,
%-------------- Scaling ------------
scale only axis,
log ticks with fixed point,
scaled ticks=false,
/pgf/number format/fixed,
%------------grid---------------
minor tick num=3,
grid=both,
grid style={line width=.1pt, draw=gray!10},
major grid style={line width=.2pt,draw=gray!50},
]
\addplot +[smooth] table [col sep=comma, x=Year,y=Host-Count] {filename.csv};
\end{axis}
\end{tikzpicture}
}%end resizebox
\end{figure}
\end{document}
我想修复 y 轴刻度。我还想保留所有数据点。我不想对值使用对数底数。有什么想法吗?
谢谢,
答案1
也许ytick=data
您想要做的是删除?(我不确定。)
代码:
\documentclass{article}
\usepackage{pgfplots}
\usepackage{filecontents}
\begin{filecontents}{filename.csv}
Month, Year, Host-Count
Jul, 1993, 1776000
Jul, 1994, 3212000
Jul, 1995, 6642000
Jul, 1996, 12881000
Jul, 1997, 19540000
Jul, 1998, 36739000
Jul, 1999, 56218000
Jul, 2000, 93047785
Jul, 2001, 125888197
Jul, 2002, 162128493
Jan, 2003, 171638297
Jul, 2004, 285139107
Jul, 2005, 353284187
Jul, 2006, 439286364
Jul, 2007, 489774269
Jul, 2008, 570937778
Jul, 2009, 681064561
Jul, 2010, 768913036
Jul, 2011, 849869781
Jul, 2012, 908585739
Jul, 2013, 996230757
Jul, 2014, 1028544414
Jul, 2015, 1033836245
Jan, 2016, 1048766623
Jul, 2017, 1074971748
\end{filecontents}
\begin{document}
\begin{figure}[h]
\centering
\resizebox{0.76\linewidth}{!}{
% \pgfplotstableread[col sep=comma]{Figures/HostsIncreaseICS.csv}\datatable
\begin{tikzpicture}
\begin{axis}[
%------------X-Axis data and style---------------
enlarge x limits=.01,
xlabel={Year},
xlabel near ticks,
xticklabel style={rotate=90,anchor=east},
xtick=data,
x tick label style={/pgf/number format/1000 sep ={} },
%------------X-Axis data and style---------------
%ytick=data,% <- remove this line
%-------------- Scaling ------------
scale only axis,
%log ticks with fixed point,
scaled ticks=false,
/pgf/number format/fixed,
%------------grid---------------
minor tick num=3,
grid=both,
grid style={line width=.1pt, draw=gray!10},
major grid style={line width=.2pt,draw=gray!50},
]
\addplot +[smooth] table [col sep=comma, x=Year,y=Host-Count] {filename.csv};
\end{axis}
\end{tikzpicture}
}%end resizebox
\end{figure}
\end{document}
如果您确实想要使用ytick=data
,并且两个连续刻度之间的距离不应取决于相关 y 值之间的差异(这对我来说似乎很奇怪),那么您必须在y expr=\coordindex
绘图和设置yticklabels from table={filename.csv}{Host-Count},
中使用axis
。此外,我会将其用于\scriptsize
刻度标签。
\documentclass{article}
\usepackage{pgfplots}
\usepackage{filecontents}
\begin{filecontents}{filename.csv}
Month, Year, Host-Count
Jul, 1993, 1776000
Jul, 1994, 3212000
Jul, 1995, 6642000
Jul, 1996, 12881000
Jul, 1997, 19540000
Jul, 1998, 36739000
Jul, 1999, 56218000
Jul, 2000, 93047785
Jul, 2001, 125888197
Jul, 2002, 162128493
Jan, 2003, 171638297
Jul, 2004, 285139107
Jul, 2005, 353284187
Jul, 2006, 439286364
Jul, 2007, 489774269
Jul, 2008, 570937778
Jul, 2009, 681064561
Jul, 2010, 768913036
Jul, 2011, 849869781
Jul, 2012, 908585739
Jul, 2013, 996230757
Jul, 2014, 1028544414
Jul, 2015, 1033836245
Jan, 2016, 1048766623
Jul, 2017, 1074971748
\end{filecontents}
\begin{document}
\begin{figure}[h]
\centering
\resizebox{0.76\linewidth}{!}{
% \pgfplotstableread[col sep=comma]{Figures/HostsIncreaseICS.csv}\datatable
\begin{tikzpicture}
\begin{axis}[
%------------X-Axis data and style---------------
enlarge x limits=.01,
xlabel={Year},
xlabel near ticks,
xticklabel style={rotate=90,anchor=east},
xtick=data,
x tick label style={/pgf/number format/1000 sep ={} },
%------------X-Axis data and style---------------
ytick=data,
yticklabels from table={filename.csv}{Host-Count},% <- added
tick label style={font=\scriptsize},% <- added
%-------------- Scaling ------------
scale only axis,
%log ticks with fixed point,
scaled ticks=false,
/pgf/number format/fixed,
%------------grid---------------
minor tick num=3,
grid=both,
grid style={line width=.1pt, draw=gray!10},
major grid style={line width=.2pt,draw=gray!50},
]
\addplot +[smooth] table [col sep=comma, x=Year,
y expr=\coordindex% <- changed
] {filename.csv};
\end{axis}
\end{tikzpicture}
}%end resizebox
\end{figure}
\end{document}
结果: