I've just tried to make a graph with grid, with GeoGebra Classic 5. I've exported the file but things didn't work as I hoped to. Could someone help to figure this out? Here I give some picture detail:

  1. First picture: The given picture I need to recreate with TikZ.

First Image

  1. Second picture: The image produced from GeoGebra.

Second Image

Here is the code for my second image:

\begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=1.0cm,y=1.0cm]
axis lines=middle,
\clip(-0.2,-1.33) rectangle (2.84,1.83);
\draw [line width=2.pt,domain=-0.2:0.0] plot(\x,{(-0.-0.*\x)/-10.});
\draw [line width=2.pt,domain=2.0:2.84] plot(\x,{(-0.-0.*\x)/9.});
\draw [line width=2.pt] (0.,1.)-- (2.,1.);
\draw [line width=2.pt,dash pattern=on 1pt off 1pt] (2.,1.)-- (2.,0.);
\draw [line width=2.pt,dash pattern=on 1pt off 1pt] (0.,1.)-- (0.,0.);
  • tex.stackexchange.com/questions/557723/…
    – js bibra
    Commented Aug 8, 2020 at 15:35
  • But, how could I name the axis though? Just like my first image?
    – Wilory Lu
    Commented Aug 8, 2020 at 16:29
  • 2
    Hi and welcome. Please add the code of your attempts.
    – AndréC
    Commented Aug 8, 2020 at 17:00
  • Sorry for the wait, I've just editted my post, hoped it help for the details.
    – Wilory Lu
    Commented Aug 9, 2020 at 4:20
  • @pluton, wow thanks for editting my question. I didn't know that I did much mistake there.
    – Wilory Lu
    Commented Aug 9, 2020 at 16:02

1 Answer 1


The image

enter image description here

is produced by

\pgfplotsset{compat=1.17} % <---

   \begin{tikzpicture}[line cap=round,line join=round]
grid=both, minor tick num=1, % <---
axis lines=middle,
xlabel=$x$, ylabel=$g(x)$,
extra x ticks={0},
tick label style={fill=white, font=\footnotesize},
xmin=-0.4,  xmax=2.8,
ymin=-1.4,  ymax=1.8,
\draw[very thick]
  (-0.4,0) -- (0,0) (0,1) -- (2,1) (2,0) -- (2.8,0); % <---
\draw[very thick, dashed] 
  (0,0) -- (0,1) (2,1) -- (2,0); % <---

The main changes in above MWE in comparison to your MWE are marked by % <---.


  • added is tick at origin, which enable to draw minor grid. It was deleted by mistake at previous editing of answer
  • extra x tick is added because diagram with used axis line=middle` doesn't enable to write tick label at origin
  • for lines are used \draw commands by which drawing straight line is simpler and faster as at using plot functions
  • Ohh, thanks a lot! But, what is MWE, though? And, I think you miss a vline on the grid, is there any way to fix that, (I mean vline on 0.5 tick) without make a tick? Oh ya, is there any reference so I could search more about fixing this case?
    – Wilory Lu
    Commented Aug 9, 2020 at 12:53
  • @WiloryLu, oh at edit of answer I by mistake deleted tick at zero. Now corrected. for reference you need to read documentation for the pdfplots. Issues about ticks are explained in section 4.15 Tick Options, pp 334 -- 352.
    – Zarko
    Commented Aug 9, 2020 at 14:04
  • OK, thanks. Looking into it.
    – Wilory Lu
    Commented Aug 9, 2020 at 15:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .