Graphics, Figures & Tablesvertical chart

Information and discussion about graphics, figures & tables in LaTeX documents.
krislodz
Posts: 42
Joined: Sun Nov 08, 2009 1:13 pm

Re: vertical chart

Post by krislodz »

It works, there is graph, but there are no descriptions on axes, it is cut to just graph area.

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

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

vertical chart

Post by localghost »

Just omit the option for auto-pst-pdf. I get the complete chart.
krislodz
Posts: 42
Joined: Sun Nov 08, 2009 1:13 pm

vertical chart

Post by krislodz »

When I use this code, the result is the same:

Code: Select all

\documentclass[spanish]{article}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage{babel}


\usepackage{ifplatform}
\usepackage{pst-pdf}
\usepackage{xkeyval}
\usepackage{auto-pst-pdf}

\deactivatetilden
\usepackage{pst-bar,pst-all,pstricks-add}
\begin{document}
\psset{xunit=1cm,yunit=1cm}%
\renewcommand*\psbarlabelsep{50pt}
\begin{pspicture}(0,0)(10,9)%
\psgrid[yunit=1cm,gridlabels=0,subgriddiv=0,griddots=30](0,0)(10,8.1)%
\psaxes[labels=all,ticks=x](0,0)(10,9)%
\readpsbardata{\graphs}{graphs.dat}%
\psbarchart[labelFontSize=2pt,shadow=true,barstyle=blue,barcolsep=0.3,orientation=horizontal]{\graphs}%
\rput(-1.4,7.5){Scatter Graphs}
\rput(-1.7,6.5){Frequency Polygon}
\rput(-1.25,5.5){Line Graphs}
\rput(-1.75,4.5){Comp. Pie Graphs}
\rput(-1.2,3.5){Pictograms}
\rput(-1.2,2.5){Histograms}
\rput(-1.2,1.5){Pie Graphs}
\rput(-1.2,0.5){Bar Charts}
\end{pspicture}
\end{document}
Maybe my package is out of date? What can be the problem.
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

vertical chart

Post by localghost »

I did a mistake and reduced your example to the absolute minimum of code. Thus I didn't use the original. One more mistake was to overlook that you include the pst-pdf package. I wonder what for. Abandon this package and it will work. And answer yourself the question what you need ifplatform and xkeyval for.
krislodz
Posts: 42
Joined: Sun Nov 08, 2009 1:13 pm

Re: vertical chart

Post by krislodz »

It is still not producing the valid pdf, the output goes to file graphs-autopp.pdf and when I try to build the original document with the graph, it is not there.
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

vertical chart

Post by localghost »

krislodz wrote:It is still not producing the valid pdf, the output goes to file graphs-autopp.pdf and when I try to build the original document with the graph, it is not there.
I wonder about this file called »graphs-autopp.pdf«. Actually there should be a file with the name »graphs-pics.pdf«. You can try a very minimal example.

Code: Select all

\listfiles
\documentclass{minimal}
\usepackage{pstricks-add}
\usepackage{auto-pst-pdf}

\begin{document}
  \psset{xunit=1cm,yunit=1cm}%
  \renewcommand*\psbarlabelsep{50pt}
  \begin{pspicture}(0,0)(10,9)%
    \psgrid[yunit=1cm,gridlabels=0,subgriddiv=0,griddots=30](0,0)(10,8.1)%
    \psaxes[labels=all,ticks=x](0,0)(10,9)%
    \readpsbardata{\graphs}{graphs.dat}%
    \psbarchart[labelFontSize=2pt,shadow=true,barstyle=blue,barcolsep=0.3,orientation=horizontal]{\graphs}%
    \rput(-1.4,7.5){Scatter Graphs}
    \rput(-1.7,6.5){Frequency Polygon}
    \rput(-1.25,5.5){Line Graphs}
    \rput(-1.75,4.5){Comp. Pie Graphs}
    \rput(-1.2,3.5){Pictograms}
    \rput(-1.2,2.5){Histograms}
    \rput(-1.2,1.5){Pie Graphs}
    \rput(-1.2,0.5){Bar Charts}
  \end{pspicture}
\end{document}
Take a look at the file list in the log file. You may have to update some packages.
krislodz
Posts: 42
Joined: Sun Nov 08, 2009 1:13 pm

Re: vertical chart

Post by krislodz »

The last snippet does not even compile to pdf, I have all packages updated.
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Re: vertical chart

Post by localghost »

I can't advice any further because it works fine for me.
feuersaenger
Posts: 34
Joined: Sun Oct 16, 2011 5:56 pm

vertical chart

Post by feuersaenger »

Hi,

a different approach might be to use pgfplots. It is based on TikZ/PGF rather than pstricks.

Here is what I got so far:
P.png
P.png (18.47 KiB) Viewed 7793 times

Code: Select all

\documentclass{standalone}
\usepackage{pgfplots}

\pgfplotsset{compat=1.5}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
	xbar,
	xmin=0,
	xtick={0,...,10},
	xmajorgrids,
	ytick=data,
	yticklabels={%
		Scatter Graphs,%
		Frequency Polygon,%
		Line Graphs,%
		Comp. Pie Graphs,%
		Pictograms,%
		Histograms,%
		Pie Graphs,%
		Bar Charts,%
	},
]

\addplot table[
	x=Value,
	% \coordindex is 0...7, 
	% but I want it upwards such that it fits
	% the yticklabels list (which is read from top to bottom).
	y expr=-\coordindex,
]
{
Value
5
1
9
4
8
3
2
5
};

\end{axis}
\end{tikzpicture}
\end{document}
The pgfplots package is a generic plotting solution which can do x bars. Axes are added using an axis environment inside of a tikzpicture environment. The xbar option configures pgfplots to draw (groups of) horizontal bar plots. The xmin=0 key tells pgfplots to start the axis (and the bar) at x=0. The ytick=data means to scan the data points of the FIRST plot and generate tick labels for every encountered y coordinate. The yticklabels key assigns the associated labels (from top to bottom).

Inside of the axis environment, it expects zero, one, or more \addplot statements. In our case, we load data from an inline table and plot the "Value" column against -\coordindex. The - sign is confusing, I admit it: it is because the list of tick labels starts at the top ... and indices start "at the bottom" (at y=0). You will understand my idea if you omit the yticklabels key.


Alternatively, you got write the labels into the very same table and load the tick labels from the table:

Code: Select all

\documentclass{standalone}
\usepackage{pgfplots}

\pgfplotsset{compat=1.5}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
	xbar,
	xmin=0,
	xtick={0,...,10},
	xmajorgrids,
	ytick=data,
	table/col sep=semicolon,
	yticklabels from table={data.dat}{Label},
]

\addplot table[
	x=Value,
	y expr=-\coordindex,
]
{data.dat};

\end{axis}
\end{tikzpicture}
\end{document}
This yields the same output if data.dat contains

Code: Select all

Value;Label
5;Scatter Graphs
1;Frequency Polygon
9;Line Graphs
4;Comp. Pie Graphs
8;Pictograms
3;Histograms
2;Pie Graphs
5;Bar Charts
note that I change the column separator to semicolon (the default would be "white space"...)
Post Reply