[pstricks] Special x-axis values

Christoph Bersch usenet at bersch.net
Thu Jul 26 09:13:04 CEST 2007


Alan Ristow schrieb:
> Christoph Bersch wrote:
>> Hi,
>>
>> I want to use special x-axis values like it's shown in 
>> http://tug.org/PSTricks/main.cgi?file=pst-plot/psaxes#ChemElements.
>>
>> My problem now is, that I have a datafile that I want to plot, and the 
>> x-values are in the range from -0.5 to 0.5 and the x-axis should have 
>> the values
>> -T/2 -T/4 0 T/4 T/2
>>
>> The following does not work properly as the indexing of the label array 
>> is wrong. How do I have to change the example?
> 
> The following works for me. I must admit that it is not entirely clear 
> to me why it is necessary to redefine *both* \pshlabel and 
> \pst@@@hlabel, and I don't really have time to look into it any further 
> just now, but it seems to do the job. Also note the changes I made to 
> your \psaxes command.

Hi,

the problem was, that the indexing of the array is done using the x-axis 
values which have to be integer. It does not work properly if you want 
to combine it with plotting data that need ticks at fractional values.

I solved it by using two different psaxes commands for xAxis and yAxis, 
and changing the xunit and \pst@@@hlabel only locally (I hope, that 
\begingroup ... \endgroup is the right way) for the xAxis command. 
Another xunit is then used again to plot the data (in my case it is done 
with \listplot, but I illustrated it with a \psplot command in the example).

Christoph

\documentclass{scrartcl}
\usepackage[T1]{fontenc}
\usepackage{pstricks-add}

\usepackage{arrayjob}
\usepackage{nicefrac}
\begin{document}
%
\newarray{\NewYLabels}
\readarray{NewYLabels}{-\nicefrac{T}{2} & -\nicefrac{T}{4} & 0 & 
\nicefrac{T}{4} & \nicefrac{T}{2}}
%
\psset{xunit=10cm}
\begin{pspicture}(-0.5,-3)(0.55,3)
\psaxes[xAxis=false,Dx=0.25]{->}(-0.55,0)(-0.5,-3.5)(0.55,3.5)
%
\begingroup
\makeatletter
\def\pst@@@hlabel#1{\NewYLabels(#1)}
\makeatother
\psset{xunit=2.5cm}
\psaxes[yAxis=false,Ox=1]{->}(-2,0)(-2.2,-3)(2.2,3)
\endgroup
%
% plot the data
\psplot{-0.5}{0.5}{x dup mul 12 mul}
\end{pspicture}
\end{document}




More information about the PSTricks mailing list