1

In the following figure I want to use legends, write $x$ labels etc. When I use \begin{axis} for these, figure becomes too large.

\begin{tikzpicture}[scale=12]
\draw [<->] (0,0.5) -- (0,0) -- (0.9,0);
\draw[black, dashed, domain=0:0.5] plot (\x, {0.25-0.5*\x});
\draw (0.053, 0.2234)--(0.1835,0.158)--(0.207,0.167)--(0.15,0.1853);
\draw[black, domain=0:0.5] plot (\x, {0.25-0.5*\x+ 0.5*\x *\x});
\draw[black, dashed, domain=0:0.5] plot (\x, {1.0+\x- 0.25*sqrt(13.0+20.0*\x +4.0*\x *\x)});
\draw ( 0.0, 0.284 )--( 0.01, 0.272 )--( 0.05, 0.227 )--( 0.054, 0.223)--(0.1, 0.178)--( 0.15, 0.136 )--(0.2, 0.101)--(0.25, 0.071 )--( 0.3, 0.047 )--( 0.35, 0.028 )--( 0.4, 0.011 )--( 0.45, 0.003 )--( 0.49, 0.0 );
\draw [color=black, fill=gray!50] (0,0.25) -- (0,0.284) -- (0.052,0.225) -- cycle;
\draw [color=black, fill=gray!50] (0.053,0.2234) -- (0.1835,0.158) -- (0.207,0.167) --(0.15,0.1853)-- cycle;
%\draw (0.4,-0.1) node{ Value of $x$};
\end{tikzpicture}
5
  • 2
    The axis environment is provided by the PGFplots package, which makes it much easier to draw plots with axes, labels, legends etc. than doing all those things "by hand" in TikZ. Can you explain in a little more detail what you mean by "figure becomes too large", and what your question is exactly?
    – Jake
    Commented Mar 29, 2012 at 16:36
  • Can you also explain why you remove the code formatting options?
    – percusse
    Commented Mar 29, 2012 at 16:39
  • I observed that when I use axis environment, I see only small part of the figure.
    – user12290
    Commented Mar 29, 2012 at 17:07
  • Percusse: Thank you very much for your help. I do not know code formatting options. Will you kindly help me how to use this?
    – user12290
    Commented Mar 29, 2012 at 17:12
  • No problem. Actually there is not much to explain: If you indent lines by 4 spaces, then they're marked as a code sample. You can also highlight the code and click the "code" button ({}) while editing your question or answer. Also you can use ticks around the code inline as Jake did in your question around $x$ with `$x$`. So they are printed as $x$. One last detail is pinging a user when you are replying, you can put an @ character, the type the few letters of the nickname and press the TAB key, the system will auto complete the name for you and it will ping the user you refer.
    – percusse
    Commented Mar 29, 2012 at 17:26

1 Answer 1

6

I have done something using axis environment but I am not sure if it is what you are looking for:

enter image description here

\documentclass{article}
\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}%[scale=1.5]
\begin{axis}[axis y line=center,
   axis x line=middle,
   x=10cm,y=10cm, % units
   xmin=-0.02,xmax=0.6,ymin=-0.02,ymax=0.5, % x and y ranges
   %xticklabels={}, yticklabels={} % no labels on ticks
   xlabel style={below=5mm}, ylabel style={left=10mm, sloped},
   xlabel=Values of $x$, ylabel=Values of $y$
]

\addplot[domain=0:0.5,mark=none,blue,dashed,samples=150] {0.25-0.5*x};
\draw (axis cs:0.053, 0.2234)
    --(axis cs:0.1835,0.158)
    --(axis cs:0.207,0.167)
    --(axis cs:0.15,0.1853);
\addplot[domain=0:0.5,mark=none,blue,dashed,samples=150] {1.0+x-0.25*sqrt(13.0+20.0*x+4.0*x^2)};
\draw[blue] (axis cs:0.0, 0.284 )
    -- (axis cs:0.01, 0.272 )
    -- (axis cs:0.05, 0.227 )
    -- (axis cs:0.054, 0.223)
    -- (axis cs:0.1, 0.178)
    -- (axis cs:0.15, 0.136)
    -- (axis cs:0.2, 0.101)
    -- (axis cs:0.25, 0.071)
    -- (axis cs:0.3, 0.047)
    -- (axis cs:0.35, 0.028)
    -- (axis cs:0.4, 0.011)
    -- (axis cs:0.45, 0.003)
    -- (axis cs:0.49, 0.0);
\addplot[domain=0:0.5,mark=none,blue,samples=150] {0.25-0.5*x+ 0.5*x^2};
\draw [color=black, fill=gray!50] (axis cs:0,0.25) 
    -- (axis cs:0,0.284)
    -- (axis cs:0.052,0.225)
    -- cycle;
\draw [color=black, fill=gray!50] (axis cs:0.053,0.2234) 
    -- (axis cs:0.1835,0.158)
    -- (axis cs:0.207,0.167)
    --(axis cs:0.15,0.1853)
    -- cycle;
\end{axis}
\end{tikzpicture}
\end{document}
1
  • 1
    Welcome to TeX.SE. In the future please keep in mind that it is best to post complete compilable examples including the \documentclass and the appropriate packages. I have done that for you here and included an image -- please edit if you did anything differently. Commented Mar 29, 2012 at 18:18

You must log in to answer this question.

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