2

Following is the code for drawing the graph of x+y=4. Now i am thinking to draw the graph of x+y=100 for that what are the necessary changes in the given codes.

\documentclass[12pt,a4paper]{article}
\usepackage[a4paper,bindingoffset=0.2in,left=0.7in,right=0.7in,top=0.7in,bottom=0.7in,footskip=.25in]{geometry}
\usepackage[centertags]{amsmath}
\usepackage{latexsym}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{newlfont}
\usepackage{enumerate}
\usepackage{makeidx}
\usepackage{tikz}
\usetikzlibrary{backgrounds,intersections}
\begin{document}
\begin{tikzpicture}
\draw[thick,latex-latex] (-2,0) -- (5,0)node[right]{$x$};
    \draw[thick,latex-latex] (0,-2) -- (0,5)node[above]{$y$};
    \node at (-0.3,-0.3) {O};
    \foreach \x in {-1,1,2,3,4}{
        \node[fill,circle,inner sep=1.5pt,label=below:$\x$] at (\x,0) {};
        \node[fill,circle,inner sep=1.5pt,label=left:$\x$] at (0,\x) {};
    }
    \draw[thick,stealth-stealth, shorten >= -2cm, shorten <= -2cm,name path =b ] (0,4) -- (4,0)
    node[pos=0.65,above,sloped] {$ $};
    \foreach \x/\y/\name in {0/4/B,4/0/A}{
        \node[fill,circle,inner sep=2.5pt,label={[inner sep=0pt]above right:\name($\x, \y$)}] at (\x,\y) {};
    }
\end{tikzpicture}
\end{document}
  • Have a look at pgfplots – JPi Dec 2 '15 at 10:27
  • For all your questions: If you have gotten answers that solve your problems, please consider accepting the best answer (by clicking the checkmark next to the answer), and upvoting any useful answers (by clicking the upward pointing arrow above the score of the answer). If you haven't gotten a good enough answer, you can edit the question to clarify it, and add comments to the answer(s) pointing at what's missing from it. – Torbjørn T. Dec 6 '15 at 22:50
3

There are several ways, one solution would be to change all coordinates to the 0 to 100 scale and fix the scaling, another would be to calculate the new labels from the given coordinates (everything times 25). Faster than that would be to fake everything by separating labels from coordinates. Example based on a more minimal version of your code below.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{intersections}
\begin{document}
\begin{tikzpicture}
\draw[thick,latex-latex] (-2,0) -- (5,0)node[right]{$x$};
    \draw[thick,latex-latex] (0,-2) -- (0,5)node[above]{$y$};
    \node at (-0.3,-0.3) {O};
    \foreach \x/\l in {-1/-25,1/25,2/50,3/75,4/100}{
        \node[fill,circle,inner sep=1.5pt,label=below:$\l$] at (\x,0) {};
        \node[fill,circle,inner sep=1.5pt,label=left:$\l$] at (0,\x) {};
    }
    \draw[thick,stealth-stealth, shorten >= -2cm, shorten <= -2cm,name path =b ] (0,4) -- (4,0)
    node[pos=0.65,above,sloped] {$ $};
    \foreach \x/\y/\name/\m/\n in {0/4/B/0/100,4/0/A/100/0}{
        \node[fill,circle,inner sep=2.5pt,label={[inner sep=0pt]above right:\name($\m, \n$)}] at (\x,\y) {};
    }
\end{tikzpicture}
\end{document}

enter image description here

But I second JPi's suggestion: Become familiar with pgfplots.

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.