0

I should draw these cartesian planes with straight lines, but I have problems in drawing the axes because they have different scales and therefore I do not know how to draw the straight lines. How can I solve this problem?

enter image description here

enter image description here

enter image description here

\documentclass[border=5mm]{standalone}
\usepackage{tkz-euclide}
\usetkzobj{all}

%   \renewcommand{\rmdefault}{phv}
%   %\usepackage{mathpple}
%   %\usepackage{palatino}
%   
%   \usepackage{lxfonts}

\begin{document}
\begin{tikzpicture}[every label/.append style={font=\Large}] 
    \npaddplus
    \tkzInit[xmin=0,ymin=0,xmax=5,ymax=5]
    \tkzGrid % moved before \tkzAxeXY
    \tkzAxeX[
       label=\hspace{4mm}\Large $\\ time [min]  $,
       very thick, % increase width of axes lines
       label options={font=\large}, % increase font size 
       orig=false % don't print zeros
    ]
    \tkzAxeY[
       label=\raisebox{4mm}{\Large $price \$ $},
       very thick, % increase width of axes lines
       label options={font=\large,}, % increase font size 
       orig=false % don't print zeros
    ]
    \node [below right=3pt,fill=white,font=\large] {$0$};
\end{tikzpicture}
\end{document}
2

Maybe pgfplots is better suited for the job. Here's something to get you started

\documentclass[]{article}

\usepackage{pgfplots}
\usetikzlibrary{fadings}

\begin{document}

% first plot
\begin{tikzpicture}
  \begin{axis}[
      domain = 0 : 250,
      xmin = 0, xmax = 250,
      ymin = 0, ymax = 350,
      xlabel = {time [min]},
      ylabel = {cost [\$]},
      axis lines = left,
      grid,
      grid style = {line width = 1pt, draw = gray!10},
    ]
  %\addplot[mark=*,blue] coordinates {(2,2) (5,8) (7,16)};
  \addplot[red, thick, path fading = east] {50 + \x};
  \end{axis}
\end{tikzpicture}


% second plot
\begin{tikzpicture}
  \begin{axis}[
      xmin = 0, xmax = 7,
      ymin = 0, ymax = 20,
      xlabel = {time [min]},
      ylabel = {cost [\$]},
      axis lines = left,
      grid,
      grid style = {line width = 1pt, draw = gray!10},
    ]
  \addplot[mark = *, red] coordinates {
    (1, 2.9)
    (2, 5.7)
    (3, 8.6)
    (4, 11.4)
    (5, 14.3)
    (6, 17.1)
    (7, 20.0)};
  \end{axis}
\end{tikzpicture}

\end{document}

enter image description here

  • thank you very much! How can I cancel the zero from y-axis? @caverac – ryuk Dec 19 '18 at 17:45
  • 1
    @ryuk Change the value of ymin – caverac Dec 19 '18 at 18:04
  • how to change the interval of y axis values? form 0,100,200 to 0,50,100,150,200? thanks a lot! – ryuk Dec 19 '18 at 18:36
  • 1
    @ryuk \begin{axis}[put here all your options], you can add there configurations for the color, number of ticks, positions, ranges, .... In particular you just need to add \begin{axis}[ytick={0, 50, 100, 150, 200}, ...] – caverac Dec 19 '18 at 22:37
  • 1
    @ryuk Sorry about that one :) Replace \addplot[red, thick, path fading = east] {50 + \x}; by \addplot[red, thick] {50 + \x}; – caverac Dec 19 '18 at 23:03

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.