I am trying to create a plot representing the number of articles about resilience over a period of time.
The data comes from a txt file, looking like this:
Publication Years Record Count % of 141519
2025 1 0.001
2024 6705 4.738
2023 19496 13.776
2022 18303 12.933
2021 17338 12.251
2020 13407 9.474
2019 11224 7.931
I only care about the first two numbers. Because it seemed that the spaces were a problem, i edited the file as such:
PublicationYears RecordCount of141519
2025 1 0.001
2024 6705 4.738
2023 19496 13.776
2022 18303 12.933
2021 17338 12.251
2020 13407 9.474
2019 11224 7.931
My objective is to plot the number of publications over time to show that the word is trendy, and maybe that it's thanks to a publication in particular. No idea why there is a 2025 row, so i ignore it. Deleting it is ok too.
Through googling and asking ChatGpt (that is a very poor tool for this by the way) i manage to end up with this
Made from the following code:
\begin{figure}
\centering
\begin{tikzpicture}
\begin{axis}[
title={Record count by Publication Years for the term "Resilience"},
bar width=0.5cm,
width=\textwidth,
height=8cm,
ylabel={Record Count},
xlabel={Publication Years},
ymin=1,
xmin=1913,
xmax=2024,
enlarge x limits={0.05},
extra x ticks = {1973},
extra x tick labels={Publication of Holling's article},
extra x tick style={grid=major,
tick label style={yshift=20pt, anchor=east}
},
scaled y ticks=false,
xtick={1910, 1920, 1930, 1940, 1950, 1960, 1970, 1980, 1990, 2000, 2010, 2020},
y tick label style={/pgf/number format/.cd,%
scaled y ticks = true,
set thousands separator={}},
x tick label style={/pgf/number format/.cd,%
scaled x ticks = false,
set thousands separator={},
fixed}%
]
\addplot+[smooth, no markers] table [x index=0, y index=1, skip first n=2] {data_sources/wos_resilience_chart.txt};
\end{axis}
\end{tikzpicture}
\caption{Record count by Publication Years for the term "Resilience" present in "Title" or "Abstract" field, when record count is at least 1. Research performed on the Web of Science database on the 15/05/2024.}
\label{fig:record_count}
\end{figure}
But this is terrible. Tinkering with the plot too much crash my document compiler, and forces me to delete everything and regenerate it all. I am also very unfamiliar with plots, so i lack a lot of lingo to even know what to look for.
I would like to :
Make the Y axis more coherent with the data; it goes from 0 to 20k, so the plot is unreadable until it already reaches a high value
Have the x axis end on the last value, but with the padding like this. I think it's cleaner
Remove the ticks on the top
Have the xmin/xmax and ymin/ymax values added automatically from the txt so that i can update it from the data instead of the code
Is there a way to do all this ?
Thanks
EDIT:
Code than should run on its own. Make sure the columns are separated by tabs and not spaces
\documentclass{article}
\usepackage{pgfplots}
\usepackage{hyperref}
\def\data{
PublicationYears RecordCount of141519
2025 1 0.001
2024 6705 4.738
2023 19496 13.776
2022 18303 12.933
2021 17338 12.251
2020 13407 9.474
2019 11224 7.931
2018 9413 6.651
2017 7879 5.567
2016 6302 4.453
2015 5221 3.689
2014 4489 3.172
2013 3315 2.342
2012 2957 2.089
2011 2529 1.787
2010 2024 1.430
2009 1777 1.256
2008 1645 1.162
2007 1194 0.844
2006 1062 0.750
2005 839 0.593
2004 679 0.480
2003 565 0.399
2002 503 0.355
2001 387 0.273
2000 376 0.266
1999 290 0.205
1998 286 0.202
1997 224 0.158
1996 181 0.128
1995 136 0.096
1994 117 0.083
1993 126 0.089
1992 110 0.078
1991 67 0.047
1990 18 0.013
1989 25 0.018
1988 18 0.013
1987 41 0.029
1986 24 0.017
1985 28 0.020
1984 19 0.013
1983 10 0.007
1982 19 0.013
1981 7 0.005
1980 17 0.012
1979 16 0.011
1978 18 0.013
1977 14 0.010
1976 11 0.008
1975 2 0.001
1974 3 0.002
1973 4 0.003
1972 2 0.001
1971 4 0.003
1969 9 0.006
1968 3 0.002
1967 1 0.001
1966 3 0.002
1965 3 0.002
1959 1 0.001
1958 2 0.001
1956 1 0.001
1955 1 0.001
1954 1 0.001
1953 1 0.001
1951 1 0.001
1950 2 0.001
1949 4 0.003
1948 2 0.001
1947 2 0.001
1946 3 0.002
1945 1 0.001
1942 1 0.001
1940 1 0.001
1937 1 0.001
1936 1 0.001
1933 1 0.001
1931 1 0.001
1919 1 0.001
1913 4 0.003
}
\begin{document}
\begin{figure}[hbt]
\centering
\begin{tikzpicture}
\begin{axis}[
title={Record count by Publication Years for the term "Resilience"},
bar width=0.5cm,
width=\textwidth,
height=7cm,
ylabel={Record Count},
xlabel={Publication Years},
ymin=1,
xmin=1913,
xmax=2024,
enlarge x limits={0.05},
extra x ticks = {1973},
extra x tick labels={Publication of Holling's article},
extra x tick style={grid=major,
tick label style={yshift=20pt, anchor=east}
},
scaled y ticks=false,
xtick={1910, 1920, 1930, 1940, 1950, 1960, 1970, 1980, 1990, 2000, 2010, 2020},
y tick label style={/pgf/number format/.cd,%
scaled y ticks = true,
set thousands separator={}},
x tick label style={/pgf/number format/.cd,%
scaled x ticks = false,
set thousands separator={},
fixed}%
]
\addplot+[smooth, no markers] table [x index=0, y index=1, skip first n=2] {data};
\end{axis}
\end{tikzpicture}
\caption{Record count by Publication Years for the term "Resilience" present in "Title" or "Abstract" field, when record count is at least 1. Research performed on the Web of Science database on the 15/05/2024.}
\label{fig:record_count}
\end{figure}
\end{document}
pgfplots
.