extract function to draw grid and x axis labels