General ⇒ pgfplots: How to use a non numeric x axis description?
-
- Posts: 7
- Joined: Sun Oct 26, 2008 9:53 am
pgfplots: How to use a non numeric x axis description?
Hi there,
is it possible to draw a bar chart like shown below?
I couldn't find in the pgfplots manual.
Any idea?
Thank you!
is it possible to draw a bar chart like shown below?
I couldn't find in the pgfplots manual.
Any idea?
Thank you!
- Attachments
-
- example.png (8.08 KiB) Viewed 9932 times
NEW: TikZ book now 40% off at Amazon.com for a short time.

- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
pgfplots: How to use a non numeric x axis description?
Perhaps this could be done with the xticklabel tag. I found an example in the pgfplots documentation that might help. In your case the format of your X axis labels is something like \Alph{\tick} or similar. Generally the documentation gives a lot of examples to get the desired result.
Best regards
Thorsten¹
Best regards
Thorsten¹
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
-
- Posts: 7
- Joined: Sun Oct 26, 2008 9:53 am
pgfplots: How to use a non numeric x axis description?
Using the example:
Doesn't work.
I need something like that instead:
or:
The axis is always a continuing number from left to right with the lowest number left and the highest to the right.
As the following example is almost what I'm searching for, I wounder if it can be realized with pgfplots:
Found at: http://www.statistiker-wg.de/pgf/tutorials/barplot.htm
Code: Select all
\begin{tikzpicture}
\begin{axis}[
ybar interval=0.9,
x tick label as interval,
xmin=2003,xmax=2030,
ymin=0,ymax=140,
xticklabel={$\Alph{\tick}$},
xtick=data,
x tick label style={rotate=90,anchor=east,/pgf/number format/1000 sep=}
]
\addplot[draw=blue,fill=blue!40!white] coordinates {
(2003,40) (2005,100) (2007,15)
(2010,90) (2020,120) (2030,3)};
\end{axis}
\end{tikzpicture}
I need something like that instead:
Code: Select all
\addplot{(1,2003-2004,40)(2,2005-2006,15)(3,2007-2009,15)(4,2010-2019,90)(5,2020-2029,120)(6,2030-2040,3)}
Code: Select all
\addplot{(1,A,40)(2,B,15)(3,C,15)(4,D,90)(5,E,120)(6,F,3)}
That's right, but I couldn't find an example giving the desired result.Generally the documentation gives a lot of examples to get the desired result.
The axis is always a continuing number from left to right with the lowest number left and the highest to the right.
As the following example is almost what I'm searching for, I wounder if it can be realized with pgfplots:
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}
-
- Posts: 7
- Joined: Sun Oct 26, 2008 9:53 am
Re: pgfplots: How to use a non numeric x axis description?
@localghost:
Please tell me the side number where you found a similar example in the pgfplots manual.
Please tell me the side number where you found a similar example in the pgfplots manual.
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
Re: pgfplots: How to use a non numeric x axis description?
Oh, of course. I failed to do that in my previous reply against my habits. It's the middle one on page 70 in Section 7.9 (Tick and Grid Options, p. 63).
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
-
- Posts: 7
- Joined: Sun Oct 26, 2008 9:53 am
pgfplots: How to use a non numeric x axis description?
Well, this one matches nearly, but doesn't work at all.
I have to display data not related by the time on the x axis (days, months, years, or else).
I can't find any example showing the x axis not related by time oder increasing numbers. But I have to use text. How can I get the Text written to the x axis every tick?
Is this possible with pgfplots?
Thank you,
Alex
P.S.: Anyway does this example make sense? The years to the next data are always shown twice (...-2003 ; 2003-...). It always has to be ...-2003 ; 2004-... otherwise it would be counted twice.
I hope this is explained well enough.
P.P.S.: I can't finde Section 34 at http://sourceforge.net/projects/pgf as shown on page 63.
I have to display data not related by the time on the x axis (days, months, years, or else).
I can't find any example showing the x axis not related by time oder increasing numbers. But I have to use text. How can I get the Text written to the x axis every tick?
Is this possible with pgfplots?
Thank you,
Alex
P.S.: Anyway does this example make sense? The years to the next data are always shown twice (...-2003 ; 2003-...). It always has to be ...-2003 ; 2004-... otherwise it would be counted twice.
I hope this is explained well enough.
P.P.S.: I can't finde Section 34 at http://sourceforge.net/projects/pgf as shown on page 63.