Graphics, Figures & TablesBar Plot with logarithmic Scale

Information and discussion about graphics, figures & tables in LaTeX documents.
elect
Posts: 5
Joined: Mon Sep 05, 2011 5:02 pm

Bar Plot with logarithmic Scale

Post by elect »

I apologize if there another thread is already opened about this, but I didnt find anything..

So, is it possible to have a bar plot with a logarithmic scale?

Recommended reading 2024:

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

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Bar Plot with logarithmic Scale

Post by localghost »

Show your recent efforts by a minimal example. Emphasize on "minimal".


Best regards and welcome to the board
Thorsten
elect
Posts: 5
Joined: Mon Sep 05, 2011 5:02 pm

Bar Plot with logarithmic Scale

Post by elect »

localghost wrote:Show your recent efforts by a minimal example. Emphasize on "minimal".


Best regards and welcome to the board
Thorsten

Sure, sorry
Like this, but instead 0-4 -> 1 -10 - 100 - 1000
barplot.png
barplot.png (38.37 KiB) Viewed 7162 times
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Bar Plot with logarithmic Scale

Post by localghost »

You obviously didn't follow the link in my last reply. Otherwise you would know that simply attached picture is no minimal example [1]. Such an example is the source of a document with minimal content that can easily be copied into an editor and compiled out of the box. Nobody is motivated to reproduce this diagram by building a complete example that might not fit your needs. Be proactive and make the first steps on your own.

For the present I suggest to take a look at packages like pgfplots (based on pgf/tikZ) or pst-plot (based on PSTricks).

[1] View topic: Avoidable mistakes
elect
Posts: 5
Joined: Mon Sep 05, 2011 5:02 pm

Bar Plot with logarithmic Scale

Post by elect »

localghost wrote:You obviously didn't follow the link in my last reply.
I know what you mean, and I did, but very quickly, because if you take care to my post, my goal is to know whether it is possible having bar plot and logarithmic axes


Btw, I think this is what you meant:

Code: Select all

\definecolor{myblue}{HTML}{92dcec}

\begin{tikzpicture}
 
  \draw (0cm,0cm) -- (15.5cm,0cm);  %Abzisse
  \draw (0cm,0cm) -- (0cm,-0.1cm);  %linkes Ende der Abzisse
  \draw (15.5cm,0cm) -- (15.5cm,-0.1cm);  %rechtes Ende der Abzisse
  
  \draw (-0.1cm,0cm) -- (-0.1cm,4.5cm);  %Ordinate
  \draw (-0.1cm,0cm) -- (-0.2cm,0cm);  %unteres Ende der Ordinate
  \draw (-0.1cm,4.5cm) -- (-0.2cm,4.5cm) node [left] {\%};  %oberes Ende der Ordinate

  \foreach \x in {1,...,4}  %Hilfslinien
    \draw[gray!50, text=black] (-0.2 cm,\x cm) -- (15.5 cm,\x cm) 
      node at (-0.5 cm,\x cm) {\x};  %Beschriftung der Hilfslinien

    \node at (7.5cm,5cm) {Wachstumsrate des realen BIP für die zehn
                           Bevölkerungsreichsten Staaten der EU 2005};  %Überschrift

  \foreach \x/\y/\country in {0.5/4.1/Rumänien,  %\x ist Anfang der Säulen
                              2/3.7/Griechenland,  %\y ist Höhe der Säulen
                              3.5/3.5/Spanien,
                              5/3.5/Polen,
                              6.5/1.9/Großbritannien,
                              8/1.5/Niederlande,
                              9.5/1.2/Frankreich,
                              11/0.9/Deutschland,
                              12.5/0.5/Portugal,
                              14/0.1/Italien}
    {
     \draw[fill=myblue] (\x cm,0cm) rectangle (1cm+\x cm,\y cm) %die Säulen
       node at (0.5cm + \x cm,\y cm + 0.3cm) {\y}; %die Prozente über den Säulen
     \node[rotate=45, left] at (0.6 cm +\x cm,-0.1cm) {\country}; %Säulenbeschriftung
    };

\end{tikzpicture}
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Bar Plot with logarithmic Scale

Post by localghost »

elect wrote:I know what you mean, and I did, but very quickly, because if you take care to my post, my goal is to know whether it is possible having bar plot and logarithmic axes […]
My impression was that you did not. And a concrete answer to your question is: „Yes. It is possible“. And you got already suggestions for two packages that can help here.
elect wrote:[…] Btw, I think this is what you meant: […]
Unfortunately it's not because not working out of the box. Since you decided to use pgf/tikZ, I again strongly recommend to have a look at the pgfplots package. It will make life easier. At the moment I have not enough time to build an example from scratch.
elect
Posts: 5
Joined: Mon Sep 05, 2011 5:02 pm

Bar Plot with logarithmic Scale

Post by elect »

localghost wrote: My impression was that you did not. And a concrete answer to your question is: „Yes. It is possible“. And you got already suggestions for two packages that can help here.
Perfect, thanks :)
localghost wrote: Unfortunately it's not because not working out of the box. Since you decided to use pgf/tikZ, I again strongly recommend to have a look at the pgfplots package. It will make life easier. At the moment I have not enough time to build an example from scratch.
I didnt really decide it, that was what I found by googling..
I have read carefully the bar plot section in the pgfplots manual (here) but I did not find anything regarding logarithmic axes..

However also the examples in that section use pgf/tikZ or am I wrong? (from page 44)
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Bar Plot with logarithmic Scale

Post by localghost »

elect wrote:[…] I have read carefully the bar plot section in the pgfplots manual (here) but I did not find anything regarding logarithmic axes.. […]
The link leads to an outdated version of the manual. A better reference is CTAN. You can also access a package manual instantly on the command line.

Code: Select all

texdoc pgfplots
elect wrote:[…] However also the examples in that section use pgf/tikZ or am I wrong? (from page 44)
The examples use of course pgfplots, which is based on pgf/tikZ (as already mentioned).

In the meantime I have worked out a minimal example. You should be able to modify it till it fits your needs.

Code: Select all

\documentclass{minimal}
\usepackage{pgfplots}

\begin{document}
  \begin{tikzpicture}
    \begin{semilogyaxis}[%
      width=14cm,height=7cm,
      ybar,
      xlabel={x axis},
      ylabel={y axis},
      xlabel near ticks,
      ylabel near ticks,
      ymin=0,ymax=1000,
      x tick label style={rotate=45,anchor=east},
      ytickten={1,2,3},
      symbolic x coords={%
        One,
        Two,
        Three,
        Four,
        Five,
        Six,
        Seven,
        Eight,
        Nine
      }
    ]
      \addplot coordinates {%
        (One,17)
        (Two,8)
        (Three,23)
        (Four,54)
        (Five,234)
        (Six,477)
        (Seven,233)
        (Eight,917)
        (Nine,121)
      };
    \end{semilogyaxis}
  \end{tikzpicture}
\end{document}
If you decide to do some similar plots, you should know that there is one important hitch. Since there is a bug concerning bar plots and logarithmic axes in the current release version 1.5, you may need the development version of the package [1,2]. However, the above example looks OK with the current stable release version.

[1] PGFPlots – A LaTeX package to create plots
[2] Logarithmisches Balkendiagramm mit pgfplots .:. goLateX – Mein LaTeX-Forum
elect
Posts: 5
Joined: Mon Sep 05, 2011 5:02 pm

Bar Plot with logarithmic Scale

Post by elect »

localghost wrote: The link leads to an outdated version of the manual. A better reference is CTAN.
Thanks
localghost wrote: In the meantime I have worked out a minimal example. You should be able to modify it till it fits your needs.

Code: Select all

\documentclass{minimal}
\usepackage{pgfplots}

\begin{document}
  \begin{tikzpicture}
    \begin{semilogyaxis}[%
      width=14cm,height=7cm,
      ybar,
      xlabel={x axis},
      ylabel={y axis},
      xlabel near ticks,
      ylabel near ticks,
      ymin=0,ymax=1000,
      x tick label style={rotate=45,anchor=east},
      ytickten={1,2,3},
      symbolic x coords={%
        One,
        Two,
        Three,
        Four,
        Five,
        Six,
        Seven,
        Eight,
        Nine
      }
    ]
      \addplot coordinates {%
        (One,17)
        (Two,8)
        (Three,23)
        (Four,54)
        (Five,234)
        (Six,477)
        (Seven,233)
        (Eight,917)
        (Nine,121)
      };
    \end{semilogyaxis}
  \end{tikzpicture}
\end{document}
If you decide to do some similar plots, you should know that there is one important hitch. Since there is a bug concerning bar plots and logarithmic axes in the current release version 1.5, you may need the development version of the package [1,2]. However, the above example looks OK with the current stable release version.
Perfect, thanks again..

I just don't know how to solve this:

Code: Select all

% Preamble: 
\begin{tikzpicture}
\begin{semilogxaxis}[
xbar,
symbolic y coords={AMD Phenom II X4 955 3.2GHz,GeForce GTX 285 },
ytick=data,
]
\addplot coordinates {(7,AMD Phenom II X4 955 3.2GHz)  (9,GeForce GTX 285) };
\addplot coordinates {(8,AMD Phenom II X4 955 3.2GHz) };
\end{semilogxaxis}
\end{tikzpicture}
You can see that some space is reserved for the second "/addplot" also for the GeForce... how can I avoid that?
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Bar Plot with logarithmic Scale

Post by localghost »

elect wrote:[…] I just don't know how to solve this: […] You can see that some space is reserved for the second "/addplot" also for the GeForce... how can I avoid that?
At the moment I have no idea. I'm not sure if this is a bug.
Post Reply