enter image description here

Lower curve is given by function y=$\left\lfloor {\frac{x+2}{2}} \right\rfloor$ and Upper curve is given by formula y=4 for x=2,3 while y=$2 \left\lceil {\frac{x}{3}} \right\rceil$

  • 2
    Is it a function of a real or integer variable? Your phrasing is not very clear. – Bernard Dec 30 '15 at 12:16
  • Positive integer variable – kalpeshmpopat Dec 30 '15 at 12:19
  • 2
    For future posts, please include an MWE, or you could rephrase to something like: "What is a good package for inputting a graph like this: (image included)?". I think you got qownvoted because it seemed like you wanted us to do all the work (plot this and that for me). – Runar Dec 30 '15 at 12:32
  • The functions are step functions. There should be only horizontal or vertical line segments. Please see my answer, in which the plots are calculated by PostScript. Unless the functions are only approximations of what you really want? – Bernard Jan 1 '16 at 1:51

You could use PGFPlots, which gives great, flexible graphs with relatively short code.

Here is something to get you going. I had some trouble understanding what you meant by your input, so it may not be correct, but you should be able to edit it to whatever your needs are.

%!tikz source begin
    every pin/.style={fill=yellow!50!white,rectangle,rounded corners=3pt,font=\tiny},
    small dot/.style={fill=black,circle,scale=0.3}
        y label style={rotate=-90},
        %title=My title,
        ylabel = $\gamma_g^e$,
        xlabel = {n=$|V(P_N)|$},
\addplot[blue, ] coordinates{(2,4) (6,4) (7,5)};
{floor(2*(x/3)+1}; % Original input{ceil(2*(x/3)};
\node[small dot,pin=-30:{$\gamma_g^e(P_6\Box P_2) = \gamma_g^e(P_6)\gamma_g^e(P_2)$}] at (6,4) {};
\legend{$\gamma_g^e(P_6\Box P_2)$,$\gamma_g^e(P_n)\gamma_g^e(P_2)$}


enter image description here

  • no problem, hope this is what you were looking for. – Runar Dec 31 '15 at 4:13
  • I had run the code in my Tex maker but I found the errors which are (! Package pgfkeys Error: Choice '1.12' unknown in choice key '/pgfplots/compat/anchors'. I am going to ignore this key.See the pgfkeys package documentation for explanation.Type H <return> for immediate help.... \pgfplotsset{width=12cm,compat=1.12} and ! Package PGF Math Error: Sorry, the operation 'ceil' has not yet been implemented in the floating point unit :-( (in 'ceil(2(x/3)').See the PGF Math package documentation for explanation.Type H <return> for immediate help.... {ceil(2(x/3)};) – kalpeshmpopat Dec 31 '15 at 11:42
  • I just want to replace N=|v(PN)| by n=|V(P_n)| and also want to remove My title. – kalpeshmpopat Dec 31 '15 at 11:47
  • Odd that ceil doesn't work, but it is probably due to an outdated TeXLive-install. How do I update my TeX distribution?I see the same problem occurs on Overleaf. Maybe you could post a new question regarding this, and some of the wizards here will come up with a great solution. In the meantime, as a one-off, you could probably replace {ceil(2*(x/3)}; by {floor(2*(x/3)+1}; which I think should give the same result. As for the x-axis, you could do `xlabel = {n=$|V(P_N)|$}, and for removing the title, just remove the line, or comment it out. – Runar Dec 31 '15 at 13:23
  • @kalpeshmpopat, I updated the example to reflect my last comment. Hope it works now. – Runar Dec 31 '15 at 14:07

Here's an effort in plain Metapost. You can find more on Metapost here.

You need to compile this with mpost -tex=latex in order to use the LaTeX package that provides the \Box symbol.

enter image description here

I've left the remaining labels and arrows for you to do :-)

prologues := 3;
outputtemplate := "%j%c.eps";


% unit of meaurement
u := 7mm;

% axes
path xx, yy;
xx = (left -- 19 right) scaled u;
yy = xx rotated 90;
for i=1 upto 18:
  draw (down--up)    shifted (i*u,0); label.bot(decimal i, (i*u,-2));
  draw (left--right) shifted (0,i*u); label.lft(decimal i, (-2,i*u));
drawarrow xx; label.rt(btex $x$ etex, point 1 of xx);
drawarrow yy; label.top(btex $y$ etex, point 1 of yy);

% functions
vardef f(expr x) = floor ((x+2)/2) enddef;
vardef g(expr x) = 2 * if x<4: 2 else: ceiling (x/3) fi enddef;

% curves
path ff, gg;
ff = ( (2,f(2)) for t=3 upto 18: -- (t,f(t)) endfor ) scaled u;
gg = ( (2,g(2)) for t=3 upto 18: -- (t,g(t)) endfor ) scaled u;

draw ff withcolor .67 red;  
for t=0 upto length ff: draw fullcircle scaled 4 shifted point t of ff; endfor 
draw gg withcolor .73 blue; 
for t=0 upto length gg: draw fullcircle scaled 4 shifted point t of gg; endfor 

% labels

z0 = (6u,4u); % point of intersection
z1 = (7u,2u);

label.rt(btex $\gamma_g^e(P_6\Box P_2) = \gamma_g^e(P_6)\gamma_g^e(P_2)$ etex, z1);
drawarrow z1 .. z0 {dir 100} cutafter fullcircle scaled 8 shifted z0;


You may take a look at MetaPost. As I can't comment for the moment, I must send it via Answer. My math professor have made a special MetaPost package for Latex to create graphs (repere.mp). The documentation is in french (sorry) : http://mirrors.ibiblio.org/CTAN/graphics/metapost/contrib/macros/repere/repere-doc.pdf

  • 1
    Now you can comment :-) – darthbith Dec 30 '15 at 12:05

These functions are step functions. Here a pstricks code to display their graphs:

\documentclass[x11names, border=3pt]{standalone}


\psset{ algebraic, arrowinset=0.2, arrowsize=3.5pt, arrowlength=1.5, linejoin=1,unit=0.6, dimen=inner}
\begin{pspicture*}(-2,-2)(20, 15)
    {\psset{linewidth=1.2pt, linecolor=DarkSeaGreen3, plotpoints=1000, dotstyle =Bo}
        \multido{\iy=4+2, \in =3+3}{5}{\multido{\ix=\in+1}{4}{\psdots(\ix,\iy)}}
        \psplot{2}{18}{floor((x + 2)/2)}
        \multido{\iy=2+1, \in=2+2}{8}{\multido{\ix=\in+1}{3}{\psdots(\ix,\iy)}}
    \psset{linecolor=SlateGray3, tickcolor=SlateGray3, ticksize=0 3pt, showorigin=false}
    \psaxes[arrows=->, labelFontSize =\scriptstyle,]{->}(19.95, 15)[x, -120][y, -140]
    \psaxes[arrows=-> , labels=none, ticks=none](-2,-2)


enter image description here

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.