2

When I do this:

\begin{figure}[h]
\centering
\footnotesize
\pgfplotsset{
   width=0.45\textwidth,  
   height=0.3\textheight,
   symbolic x coords={2007,2008,2009,2010,2011,2012,2013,2014,2015,2016,2017,2018},  
   %enlarge y limits={upper,value=0.05},  
   }
\begin{tikzpicture}

\begin{axis}[
   xtick=\empty,
   xticklabels={2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018},
    ybar,                         
   bar width=0.2cm,               
   ymin=0, ymax=1200,
   ytick={0, 200, 400, 600, 800, 1000, 1200},
   ylabel style={align=center},
   ylabel={Number of publication containing the keywords \\ ``ciprofloxacin + resistance''},
   xticklabel style={
      inner sep=0pt,
      anchor=north east,
      rotate=60
      },
   ]
    \addplot[thick,fill=baishu,draw=baishu] plot coordinates{
     (2007,888) (2008,908) (2009,920) (2010,1010) (2011,1003) (2012,1081) (2013,1082) (2014,1075) (2015,1092) (2016,1100) (2017,1049) (2018,789)  %%%resist
      };
   \end{axis}

\end{tikzpicture}

\label{resist}
\end{figure}

enter image description here

there is no x labels.

When I do this:

\begin{figure}[h]
\centering
\footnotesize
\pgfplotsset{
   width=0.45\textwidth,  %图片尺寸
   height=0.3\textheight,
   symbolic x coords={2007,2008,2009,2010,2011,2012,2013,2014,2015,2016,2017,2018},  %X轴定义
   %enlarge y limits={upper,value=0.05},  %Y轴顶端的距离
   }
\begin{tikzpicture}

\begin{axis}[
   xtick={2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018},
   xticklabels={2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018},
    ybar,                         %柱状图
   bar width=0.2cm,               %柱子宽度
   ymin=0, ymax=1200,
   ytick={0, 200, 400, 600, 800, 1000, 1200},
   ylabel style={align=center},
   ylabel={Number of publication containing the keywords \\ ``ciprofloxacin + resistance''},
   xticklabel style={
      inner sep=0pt,
      anchor=north east,
      rotate=60
      },
   ]
    \addplot[thick,fill=baishu,draw=baishu] plot coordinates{
     (2007,888) (2008,908) (2009,920) (2010,1010) (2011,1003) (2012,1081) (2013,1082) (2014,1075) (2015,1092) (2016,1100) (2017,1049) (2018,789)  %%%resist
      };
   \end{axis}

\end{tikzpicture}

\label{resist}
\end{figure}

enter image description here the little bars above can't be removed...

besides, how to put those x axis little bars inner side?

enter image description here

  • 1
    Sorry, what is your question? Do you want to remove the bars or move them to the inner side? – user121799 Oct 9 '18 at 4:01
  • 1
    BTW, does this answer help you? – user121799 Oct 9 '18 at 4:08
1

Here is one possibility: use xtick align=inside, after ybar.

\documentclass{article}
\usepackage[margin=1in]{geometry}
\usepackage{pgfplots}
\begin{document}
\pgfplotsset{compat=1.16,axis on top,
   width=0.45\textwidth,  
   height=0.3\textheight,
   symbolic x coords={2007,2008,2009,2010,2011,2012,2013,2014,2015,2016,2017,2018},  %X___
   %enlarge y limits={upper,value=0.05}, 
   }
\begin{tikzpicture}
\begin{axis}[tick pos=left,
   xtick={2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018},
   xticklabels={2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018},
   ybar,     
   xtick align=inside,                    
   bar width=0.2cm,               
   ymin=0, ymax=1200,
   ytick={0, 200, 400, 600, 800, 1000, 1200},
   ylabel style={align=center},
   ylabel={Number of publication containing the keywords \\ ``ciprofloxacin + resistance''},
   xticklabel style={
      inner sep=2pt,
      anchor=north east,
      rotate=60
      },
   ]
    \addplot[thick,fill=blue,draw=blue] plot coordinates{
     (2007,888) (2008,908) (2009,920) (2010,1010) (2011,1003) (2012,1081) (2013,1082) (2014,1075) (2015,1092) (2016,1100) (2017,1049) (2018,789)  %%%resist
      };
   \end{axis}
\end{tikzpicture}
\end{document}

enter image description here

  • Thank you very much, this is exactly what I want. God bless you. – Liam Chang Oct 9 '18 at 12:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.