Unterschiedliche Farben im Säulendiagramm

Tabellen und Grafiken erstellen und anordnen


sashavaia
Forum-Newbie
Forum-Newbie
Beiträge: 2
Registriert: Do 21. Mai 2015, 10:50

Unterschiedliche Farben im Säulendiagramm

Beitrag von sashavaia »

Hallo zusammen,

ich wuerde gerne ein Säulendiagramm erstellen.
Ich habe den unten stehenden Code benutzt:
\begin{figure}[h]
	\centering
 	\begin{tikzpicture}
	\begin{axis}[
	axis lines=left,
    ybar stacked,       
    enlargelimits=0.1,
    nodes near coords,
	%nodes near coords align={horizontal},
    legend style={at={(1.4,-0.50)},
      anchor=north,legend columns=-1},
    ylabel={GW},
    symbolic x coords={Cina, USA, Brasile, Germania, 
		Canada, Giappone, India, Italia, Russia, Spagna},
    xtick=data,
      x tick label style={rotate=48,anchor=east},
    width=13cm,
    height=8cm,
    legend style={cells={anchor=west},legend pos=north east}
    ]
    \node[coordinate,pin=right :{454.8}] at (axis cs:Cina,454.8) {};
     \node[coordinate,pin=above :{203.5}] at (axis cs:USA,203.5) {};
      \node[coordinate,pin=above :{107.5}] at (axis cs:Brasile,107.5) {};
       \node[coordinate,pin=above :{97.4}] at (axis cs:Germania,97.4) {};
        \node[coordinate,pin=above :{89.5}] at (axis cs:Canada,89.5) {};
         \node[coordinate,pin=above :{79.6}] at (axis cs:Giappone,79.6) {};
          \node[coordinate,pin=above :{75.3}] at (axis cs:India,75.3) {};
           \node[coordinate,pin=above :{54.0}] at (axis cs:Italia,54.0) {};
            \node[coordinate,pin=above :{51.3}] at (axis cs:Russia,51.3) {};
             \node[coordinate,pin=above :{50.2}] at (axis cs:Spagna,50.2) {};
\addplot+[ybar] plot coordinates {(Cina,454.8) (USA,203.5) 
  (Brasile,107.5) (Germania,97.4) (Canada,89.5) (Giappone,79.6) (India,75.3) (Italia,54.0) (Russia,51.3) (Spagna,50.2)};

\legend{cumulato}
\end{axis}
\end{tikzpicture}
\caption{Top 10 Paesi nel 2014 per capacità cumulata}
\label{fig: capacità2014}
\end{figure}
Mein Problem ist, dass ich gerne bei jede Säule eine andere Farbe anzeigen lassen will, aber hier die gleiche Farbe haben.
Hat jemand einen Loesungsvorschlag?

Vielen Dank.[/code]

Bartman
Forum-Meister
Forum-Meister
Beiträge: 2466
Registriert: Do 16. Jul 2009, 21:41
Wohnort: Hessische Provinz

Beitrag von Bartman »

Dieser Quelltext erzeugt bei Dir eine PDF-Datei?

sashavaia
Forum-Newbie
Forum-Newbie
Beiträge: 2
Registriert: Do 21. Mai 2015, 10:50

Beitrag von sashavaia »

js es wird ein PDF erzeugt, sie sind aber einfarbig...
Der Anfaeger glaubt an jeden inzelnen Ziffer.
Der Programmiert vertraut auf die Haelfte der Stelle.
Der Wissende misstraut dem Vorzeichen.

Besserwisser

Beitrag von Besserwisser »

sashavaia hat geschrieben:js es wird ein PDF erzeugt, sie sind aber einfarbig...
Seltsam, bei mir ergibt das ja nur
Running `LaTeX' on `test' with ``pdflatex --synctex=1 -interaction=nonstopmode "\input" test.tex''
This is pdfTeX, Version 3.14159265-2.6-1.40.16 (TeX Live 2015) (preloaded format=pdflatex)
 restricted \write18 enabled.
entering extended mode
LaTeX2e <2015/01/01>
Babel <3.9l> and hyphenation patterns for 79 languages loaded.
(./test.tex

! LaTeX Error: Environment figure undefined.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              
                                                  
l.1 \begin{figure}
                  [h]

! LaTeX Error: Missing \begin{document}.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              
                                                  
l.1 \begin{figure}[
                   h]

! LaTeX Error: Environment tikzpicture undefined.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              
                                                  
l.3 \begin{tikzpicture}
                       

! LaTeX Error: Environment axis undefined.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              
                                                  
l.4 \begin{axis}
                [
! Undefined control sequence.
l.21 \node
          [coordinate,pin=right :{454.8}] at (axis cs:Cina,454.8) {};
! Undefined control sequence.
l.22 \node
          [coordinate,pin=above :{203.5}] at (axis cs:USA,203.5) {};
! Undefined control sequence.
l.23 \node
          [coordinate,pin=above :{107.5}] at (axis cs:Brasile,107.5) {};
! Undefined control sequence.
l.24 \node
          [coordinate,pin=above :{97.4}] at (axis cs:Germania,97.4) {};
! Undefined control sequence.
l.25 \node
          [coordinate,pin=above :{89.5}] at (axis cs:Canada,89.5) {};
! Undefined control sequence.
l.26 \node
          [coordinate,pin=above :{79.6}] at (axis cs:Giappone,79.6) {};
! Undefined control sequence.
l.27 \node
          [coordinate,pin=above :{75.3}] at (axis cs:India,75.3) {};
! Undefined control sequence.
l.28 \node
          [coordinate,pin=above :{54.0}] at (axis cs:Italia,54.0) {};
! Undefined control sequence.
l.29 \node
          [coordinate,pin=above :{51.3}] at (axis cs:Russia,51.3) {};
! Undefined control sequence.
l.30 \node
          [coordinate,pin=above :{50.2}] at (axis cs:Spagna,50.2) {};
! Undefined control sequence.
l.31 \addplot
             +[ybar] plot coordinates {(Cina,454.8) (USA,203.5)

Overfull \hbox (20.0pt too wide) in paragraph at lines 1--33
 [] 
! Undefined control sequence.
l.34 \legend
            {cumulato}

! LaTeX Error: Missing \begin{document}.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              
                                                  
l.34 \legend{c
              umulato}

! LaTeX Error: \begin{document} ended by \end{axis}.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              
                                                  
l.35 \end{axis}
               

! LaTeX Error: \begin{document} ended by \end{tikzpicture}.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              
                                                  
l.36 \end{tikzpicture}
                      

! LaTeX Error: \caption outside float.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              
                                                  
l.37 \caption
             {Top 10 Paesi nel 2014 per capacità cumulata}

! LaTeX Error: \begin{document} ended by \end{figure}.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              
                                                  
l.39 \end{figure}
                 
)
! Emergency stop.
<*> \input test.tex
                   
!  ==> Fatal error occurred, no output PDF file produced!
Transcript written on test.log.

LaTeX exited abnormally with code 1 at Fri Jul  3 22:32:53
Ehrlich gesagt, glaube ich nicht, dass das bei dir anders ist. Du solltest vielleicht den Link, den dir Bartman gegeben hat, mal genauer in Augenschein nehmen …

esdd
Forum-Meister
Forum-Meister
Beiträge: 2561
Registriert: So 7. Feb 2010, 16:36

Beitrag von esdd »

Wenn jede Säule eine andere Farbe haben soll, dann musst Du jede Säule einzeln plotten. Da bei mehreren ybar Plots in einer axis Umgebung die Balken mit unterschiedlichen Verschiebungen um die x-Werte eingetragen werden, musst Du dann entweder bis auf beim letzten Plot überall forget plot mit angeben und dafür dann wieder die Farbe manuell wählen. Oder Du legst mehrere axis Umgebungen übereinander, aber auch da muss die Farbe dann einzeln festgelegt werden. Wozu brauchst Du die Farben überhaupt? Sie scheinen doch keine zusätzliche Info zu enthalten.

Warum Du an jeden Balken den y-Wert nochmal von Hand schreibst, verstehe ich auch nicht. Du verwendest doch schon nodes near coords?

Gruß
Elke

PS: Wie die anderen schon gesagt haben, Dein Beispiel ist nicht lauffähig.

Antworten