Graphics, Figures & TablesProblems with a graph...

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
pointeddot
Posts: 11
Joined: Thu Jun 27, 2013 1:16 am

Problems with a graph...

Post by pointeddot »

Hey,

I want to "draw" a function in TexShop.

Unfortunately I have two problems:
1. How do I get the points in this increasing distance? I have been searching for a while, but I cannot find a solution for my problem.
2. How do I get the color right? Cyan is pretty close, but not the right colour?

This is what I had so far:

Code: Select all

\documentclass[11pt]{article}

\usepackage{pstricks,pst-all}

\begin{document}
Example

\newpage

\section*{Aufgabe 5}
\section*{\markboth{Aufgabe 5}}
\addcontentsline{toc}{section}{Aufgabe 5}
\begin{figure}[h]
\centering
\psset{xunit=0.75cm,yunit=0.011cm}
\begin{pspicture}(-10,-1000)(10,1000)
\psaxes[Dy=100,showorigin=false, mathLabel=false]{<->}(0,0)(-10,-1000)(10,1000)
\psset{algebraic=true}
\psplot[plotstyle=line,linestyle=dotted,linecolor=cyan,linewidth=0.1cm]{-10}{10}{(x^3)-0.125*(x^2)}
\rput(10.5,0){$ s $}
\rput(10.8,1000){$ K(s) $}
\end{pspicture}
\caption[Abbildung 2: Funktionen plotten]{Aufgabe 5: Funktionen plotten}
\end{figure}



\end{document}

Thank you very much!
Attachments
Bildschirmfoto 2013-06-27 um 01.05.02.png
Bildschirmfoto 2013-06-27 um 01.05.02.png (37.71 KiB) Viewed 6595 times
Last edited by cgnieder on Thu Jun 27, 2013 11:44 am, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Problems with a graph...

Post by Johannes_B »

pointeddot wrote: 1. How do I get the points in this increasing distance? I have been searching for a while, but I cannot find a solution for my problem.
2. How do I get the color right? Cyan is pretty close, but not the right colour?
Could you please be more specific about what you are trying to accomplish?
What incresing distance? What would be the right color? All this is part of an adequate problem description.

And please read about Minimal working examples and provide a proper one in your next post using the code-button.


Do you know the pgfplots-package?

Code: Select all

\documentclass[11pt]{article}

\usepackage{pstricks,pst-all}
\usepackage{auto-pst-pdf}
\usepackage{pgfplots}
\begin{document}
\scalebox{0.8}{
\psset{xunit=0.75cm,yunit=0.011cm}
\begin{pspicture}(-10,-1000)(10,1000)
  \psaxes[Dy=100,showorigin=false,
  mathLabel=false]{<->}(0,0)(-10,-1000)(10,1000)
  \psset{algebraic=true}
  \psplot[plotstyle=line,linestyle=dotted,linecolor=cyan,linewidth=0.1cm]{-10}{10}{(x^3)-0.125*(x^2)}
  \rput(10.5,0){$ s $}
  \rput(10.8,1000){$ K(s) $}
\end{pspicture}
}

\begin{tikzpicture}
  \begin{axis}[xlabel={$s$},
    ylabel={$K(s)$}]
    \addplot+[samples=20]
    {(x^3)-0.125*(x^2)};
  \end{axis}
\end{tikzpicture}
\end{document}
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
pointeddot
Posts: 11
Joined: Thu Jun 27, 2013 1:16 am

Re: Problems with a graph...

Post by pointeddot »

Dear Johannes,
thank you for your quick answer.

What i mean by the increasing distance is that the distance between the dots is increasing the farer the functions gets away from (0/0). Pretty hard to explain.
I will attach you a screenshot of the function I drew so far. I think you will now know what I mean by increasing distance.

I was searching for examples, which might help me (also in the pgfplots-package), but I could not find my problem here.

I guess, that only a little command is missing. I got "linestyle=dotted". There should be another small command.

Thank you very much!
Attachments
Bildschirmfoto 2013-06-27 um 16.13.15.png
Bildschirmfoto 2013-06-27 um 16.13.15.png (33.19 KiB) Viewed 6577 times
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Problems with a graph...

Post by localghost »

For the result you want to achieve you need the option plotstyle=dots (combined with e.g. dotsize=4pt here) instead of the style you have chosen.

Code: Select all

% !TeX program = pdflatex
\documentclass[11pt]{standalone}
\usepackage[T1]{fontenc}
\usepackage{pst-plot,pstricks-add}
\usepackage{auto-pst-pdf}  % allow PSTricks code with PDFLaTeX

\begin{document}
  \psset{xunit=0.75cm,yunit=0.01cm}
  \begin{pspicture}(-10,-1000)(10,1000)
    \psaxes[Dy=100,showorigin=false,mathLabel=false]{<->}(0,0)(-10,-1000)(10,1000)[$s$,0][$K(s)$,90]
    \psplot[algebraic=true,plotstyle=dots,dotsize=4pt,linecolor=teal]{-10}{10}{(x^3)-0.125*(x^2)}
  \end{pspicture}
\end{document}
In fact there is a constant distance of the dots in x direction. This purports that the dots on the actual plot curve move apart with increasing slop of the curve.

The color of the dots in the first picture you attached is simply "blue". In the the above code the color "teal" has been chosen, a predefined color of xcolor. Perhaps you should read in its documentation to get the color of your choice.


Best regards and welcome to the board
Thorsten
Attachments
tmp.png
tmp.png (5.72 KiB) Viewed 6571 times
pointeddot
Posts: 11
Joined: Thu Jun 27, 2013 1:16 am

Problems with a graph...

Post by pointeddot »

Thank you for your post! This one was really important for me.
I now got it this way:

Code: Select all

\documentclass[11pt]{article}
\usepackage{pstricks,pst-all}
\begin{document}
\section*{Aufgabe 5}
\section*{\markboth{Aufgabe 5}}
\addcontentsline{toc}{section}{Aufgabe 5}
\begin{figure}[h]
\centering
\psset{xunit=0.75cm,yunit=0.011cm}%definiert die Dimension der X- und Y-Einheiten 
\begin{pspicture}(-10,-1000)(10,1000)% Definiert die Arbeitsumgebung 
\psaxes[Dy=100,showorigin=false, mathLabel=false]{<->}(0,0)(-10,-1000)(10,1000)%erzeugt die Koordinatenachsen
\psset{algebraic=true}
\psplot[algebraic=true,plotstyle=dots,dotsize=4pt,linecolor=blue]{-10}{10}{(x^3)-0.125*(x^2)}
\rput(10.5,0){$ s $}%erzeugt die X-Achsenbeschriftung
\rput(10.8,1000){$ K(s) $}%erzeugt die Funktionsbeschriftung
\end{pspicture}
\caption[Abbildung 1: Daten plotten]{\textcolor{cyan}{Aufgabe 5: Daten plotten}}
\end{figure}
\end{document}

I still have three problems:
1. I would like to write: "Abbildung 1: Aufgabe 5: Funktionen plotten" under the graph; somehow the program automatically replaces "Abbildung" by "figure"
2. "Aufgabe 5" is supposed to be read at the left top position, but somehow one the one page you can read "Aufgabe 5" and on the other one, you will see the graph. So I guess the graph is too big. But how do I shrink it?
3. the graph is not really in the middle. It seems a little bit too much on the right side. How can I control it?


Thank you very much!
Attachments
Bildschirmfoto 2013-07-01 um 14.30.51.png
Bildschirmfoto 2013-07-01 um 14.30.51.png (33.76 KiB) Viewed 6532 times
Last edited by cgnieder on Tue Jul 02, 2013 6:16 pm, edited 1 time in total.
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Problems with a graph...

Post by Johannes_B »

Hi, you need to load the language package babel with the option ngerman.

Code: Select all

\documentclass[11pt]{article}
\usepackage{pstricks,pst-all}
\usepackage{auto-pst-pdf} % allow PSTricks code with PDFLaTeX
\usepackage[ngerman]{babel}
\usepackage{showframe}
\begin{document}
\section*{Aufgabe 5}% Is there
\section*{\markboth{Aufgabe 5}}% a reason for
\addcontentsline{toc}{section}{Aufgabe 5}% doing this?
\begin{figure}[h]% this is very resrictive, you should leave it out and do all the fine-tuning at the end
  \centering
  \scalebox{0.6}{
  \psset{xunit=0.75cm,yunit=0.011cm}%definiert die Dimension der X- und Y-Einheiten
  \begin{pspicture}(-10,-1000)(10,1000)% Definiert die Arbeitsumgebung
    \psaxes[Dy=100,showorigin=false,
    mathLabel=false]{<->}(0,0)(-10,-1000)(10,1000)%erzeugt die Koordinatenachsen
    \psset{algebraic=true}
    \psplot[algebraic=true,plotstyle=dots,dotsize=4pt,linecolor=blue]{-10}{10}{(x^3)-0.125*(x^2)}
    \rput(10.5,0){$ s $}%erzeugt die X-Achsenbeschriftung
    \rput(10.8,1000){$ K(s) $}%erzeugt die Funktionsbeschriftung
  \end{pspicture}}
  \caption[%Abbildung 1: <- LaTeX does that for you, this is also just for the list of figures
 Daten plotten]{\textcolor{cyan}{Aufgabe
  5: Daten plotten}}
\end{figure}
\end{document}
How to scale down the picture is already shown in my first answer. Is there a reason for not using a KOMA-class?

I recommend to read an introduction to LaTeX.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Problems with a graph...

Post by localghost »

Actually the follow-up questions are not related to the original problem. But as we are on the subject …
pointeddot wrote:[…] the graph is not really in the middle. It seems a little bit too much on the right side. How can I control it? […]
That's because it is just too big. You should get corresponding warnings in the log file (*.log).

Try the psgraph environment from pst-plot. It allows an arbitrary scale of the graph without much effort. Needs XeLaTeX or LaTeX→DVI→PS→PDF (therefore "Open in writeLaTeX" won't work). The output is attached.

Code: Select all

\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage{pst-plot,pstricks-add}

\begin{document}
  \psset{xAxisLabel={$s$},yAxisLabel={$K(s)$}}
  \begin{psgraph}[
    Dy=100,
    showorigin=false,
    mathLabel=false,
    labelFontSize=\footnotesize
  ]{->}(0,0)(-10,-1000)(10,1000){0.8\textwidth}{0.8\textheight}
    \psplot[algebraic=true,plotstyle=dots,dotsize=4pt,linecolor=blue]{-10}{10}{(x^3)-0.125*(x^2)}
    \rput[r](9,950){$x^3-0.125\,x^2$}
  \end{psgraph}
\end{document}
For the options of that environment and possible settings by \psset please refer to the package manual.
Attachments
tmp.png
tmp.png (6.84 KiB) Viewed 6520 times
Post Reply