Matthew Leingang | 4 May 20:33
Picon
Gravatar

Random permutation of a list

Hi,

I'm just getting into the pgfmath package more.  Good stuff!

I'm writing an exam and would like to randomly permute the order of  
multiple-choice items.  I was thinking of using the  
\pgfmathdeclarerandomlist command and then writing something to do a  
Knuth shuffle: for each i from 1 to n, choose a random number j from 1  
to n, then swap position i and j.

Before I get too deep, has anyone done this or something like this  
before?

TIA,
Matt

--
Matthew Leingang
Clinical Associate Professor of Mathematics
leingang <at> courant.nyu.edu

------------------------------------------------------------------------------
Register Now & Save for Velocity, the Web Performance & Operations 
Conference from O'Reilly Media. Velocity features a full day of 
expert-led, hands-on workshops and two days of sessions from industry 
leaders in dedicated Performance & Operations tracks. Use code vel09scf 
and Save an extra 15% before 5/3. http://p.sf.net/sfu/velocityconf
Charles-Axel Dein | 6 May 13:06
Picon

Create a bar diagram with Tikz

Hi,

I'm trying to create a bar diagram. I could have used the ycomb
options, yet I want to create a compound bar chart, that is to say
with subdivided bars.

I created it totally manually, but now I want to add labels inside the
bars. Because I've done this inefficiently, it seems very difficult.
Perhaps you have a more efficient way of doing this. I tried searching
the web as well as http://www.texample.net/tikz/, which I found very
interesting.

Thank you very much,

Charles

##
\begin{tikzpicture}[font=\footnotesize, thick, text badly centered,
sav/.style={color=black!50,fill},
ib/.style={color=black!35,fill},
cg/.style={color=black!20,fill},
every node/.style={anchor=north}]

\draw[->,gray,thin] (0,0) -- (0,3.75);
\draw[gray,thin] (0,0) -- (9,0);
\path (0,3.75/2) node [left] {Value};

% I would like to insert a centered label inside
% this rectangle. This label should be vertically and horizontally
% centered.
(Continue reading)

Mark Wibrow | 6 May 13:19

Re: Random permutation of a list

Hi,

I wouldn't try to use the random list stuff. Just implement a
different list structure and access it using random integers. The
following demonstrates the sort of thing that could do it:

\documentclass{article}
\usepackage{tikz}

\begin{document}

\makeatletter
\def\pgfmathdeclarelist#1#2{%
	\def\pgfmath <at> list <at> name{#1}%
	\c <at> pgfmath <at> counta=0%
	\pgfmath <at> declarelistlist#2{\pgfmath <at> stop}%
}%
\def\pgfmath <at> declarelistlist#1{%
	\ifx#1\pgfmath <at> stop%
		\expandafter\edef\csname pgfmath <at> list@\pgfmath <at> list <at> name
@length\endcsname{\the\c <at> pgfmath <at> counta}%
	\else%
		\advance\c <at> pgfmath <at> counta by1\relax%
		\pgfutil <at> namedef{pgfmath <at> list@\pgfmath <at> list <at> name @\the\c <at> pgfmath <at> counta}{#1}%
		\expandafter\pgfmath <at> declarelistlist%
	\fi%
}

\def\pgfmathgetlistitem#1#2#3{\expandafter\let\expandafter#1\expandafter=\csname
pgfmath <at> list@#2@#3\endcsname}
(Continue reading)

Matthew Leingang | 6 May 14:27
Picon
Gravatar

Re: Random permutation of a list

Dear Mark,

[Hope this isn't too off topic.  Is there a pgfmath-users list?]

Thanks for helping me clean that up.  You're right; I should just use  
a separate class for lists.

Your implementation has a flaw that mine also had.  If I replace the  
list declaration with

    \pgfmathdeclarelist{mylist}{{A}{B}{C}{D}{E}{F}{G}{H}{I}{J}{K}{L}{$ 
\sqrt{2}$}}

I get

    ! Argument of \XC <at> definec <at> lor has an extra }.
    <inserted text>
                    \par
    l.59 }

Or if I change it to

    \pgfmathdeclarelist{mylist}{{A}{B}{C}{D}{E}{F}{G}{H}{I}{J}{K}{L}{{$ 
\frac{A}{B}$}}}

I get

    ! Missing \endcsname inserted.
    <to be read again>
                       \begingroup
(Continue reading)

Mark Wibrow | 6 May 14:55

Re: Random permutation of a list

Hi,

Actually you can use them in the list, you just can't use them as node
names (which my example relied on):

\documentclass{article}
\usepackage{tikz}

\begin{document}

\makeatletter
\def\pgfmathdeclarelist#1#2{%
	\def\pgfmath <at> list <at> name{#1}%
	\c <at> pgfmath <at> counta=0%
	\pgfmath <at> declarelistlist#2{\pgfmath <at> stop}%
}%
\def\pgfmath <at> declarelistlist#1{%
	\ifx#1\pgfmath <at> stop%
		\expandafter\edef\csname pgfmath <at> list@\pgfmath <at> list <at> name
@length\endcsname{\the\c <at> pgfmath <at> counta}%
	\else%
		\advance\c <at> pgfmath <at> counta by1\relax%
		\pgfutil <at> namedef{pgfmath <at> list@\pgfmath <at> list <at> name @\the\c <at> pgfmath <at> counta}{#1}%
		\expandafter\pgfmath <at> declarelistlist%
	\fi%
}

\def\pgfmathgetlistitem#1#2#3{\expandafter\let\expandafter#1\expandafter=\csname
pgfmath <at> list@#2@#3\endcsname}

(Continue reading)

Piero D'Ancona | 6 May 18:53
Picon

bounding box woes


Greetings. I am trying to produce a one page pdf file containing
a single picture, without white margins, i.e. trimmed to contain
exactly the image, down to its bounding box. So, consider the
following minimal code:

%----------------------------------
\documentclass{article}\usepackage{pgfplots}
\newlength{\myheight}\newlength{\mywidth}\pagestyle{empty}

\mywidth=10truecm
\myheight=7truecm

\usepackage[right=0pt,top=0pt,
paperwidth=\mywidth,paperheight=\myheight]{geometry}
\parindent=0pt

\begin{document}
\begin{tikzpicture}
  \begin{axis}
    [width=\mywidth, height=\myheight,
    axis x line=center,axis y line=center]
  \addplot[blue]
    expression[domain=-5:5]{x^2};
  \end{axis}
\end{tikzpicture}
\end{document}
%----------------------------------

I get an image perfectly trimmed at the top and
(Continue reading)

Piero D'Ancona | 6 May 19:13
Picon

Re: bounding box woes


Ooookay, it is sufficient to use

\usepackage[pdftex,active,tightpage]{preview}

and enclose the image between \begin{preview}...\end{preview}

Package geometry not necessary

Bye
Piero

--

-- 
View this message in context: http://www.nabble.com/bounding-box-woes-tp23361273p23411357.html
Sent from the pgf-users mailing list archive at Nabble.com.

------------------------------------------------------------------------------
The NEW KODAK i700 Series Scanners deliver under ANY circumstances! Your
production scanning environment may not be a perfect world - but thanks to
Kodak, there's a perfect scanner to get the job done! With the NEW KODAK i700
Series Scanner you'll get full speed at 300 dpi even with all image 
processing features enabled. http://p.sf.net/sfu/kodak-com
Charles-Axel Dein | 7 May 11:05
Picon

Re: Create a bar diagram with Tikz

I managed to create a bar diagram, but I have a slight problem
regarding yshift. The bar parts are not connected, there is a small
amount of space between them. I guess it comes from measure units.

###
\documentclass{article}
\usepackage{xcolor,tikz}

\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}[y=0.03cm,%
% STYLES
font=\footnotesize, text badly centered]
% Model name/SAV/IB/CG
\def\designvalues{0/Microsoft's model/25/60/40,1/Alternative
model/50/20/10,2/Google's model/60/5/10}
\def\colwidth{0.3}

%\foreach \y in {0,20,40,60,80,100}
%\node (0,\y) node[left] {\y};

\draw[->] (0,0) -- (0,130);
\draw (0,0) -- (6,0);

\foreach \i/\xtext/\sav/\ib/\cg in \designvalues
{
\def\x{40+\i*2.5}

\begin{scope}[xshift=\x cm]
(Continue reading)

Charles-Axel Dein | 7 May 11:22
Picon

Re: Create a bar diagram with Tikz

Ok, it must be an awful solution, but I can't find another one. My bar
diagram is finished, but there must be a LOT of optimisation, since I
am an absolute beginner with Tikz.

###
\documentclass{article}
\usepackage{xcolor,tikz}

\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}[y=0.03cm,%
% STYLES
font=\footnotesize, text badly centered,
inside/.style={color=white},]
% Model name/SAV/IB/CG
\def\designvalues{0/Microsoft's model/25/65/40,1/Alternative
model/50/25/20,2/Google's model/60/15/20}
\def\colwidth{0.4}
\def\maxy{150}

\draw[->] (0,0) -- (0,\maxy);
\path (-0.25,\maxy/2) node [left] {Value};
\draw (0,0) -- (8,0);

\foreach \i/\xtext/\sav/\ib/\cg in \designvalues
{
\def\x{40+\i*2.5}

\begin{scope}[xshift=\x cm]
(Continue reading)

Picon
Favicon

Re: Create a bar diagram with Tikz

Did you try to use pgfplots ? I think it's got everything you need to do 
such charts. Take a look at the manual : 
http://www.ctan.org/tex-archive/graphics/pgf/contrib/pgfplots/doc/latex/pgfplots/pgfplots.pdf

Sebastian

Charles-Axel Dein a écrit :
> Ok, it must be an awful solution, but I can't find another one. My bar
> diagram is finished, but there must be a LOT of optimisation, since I
> am an absolute beginner with Tikz.
>
> ###
> \documentclass{article}
> \usepackage{xcolor,tikz}
>
> \begin{document}
> \begin{figure}
> \centering
> \begin{tikzpicture}[y=0.03cm,%
> % STYLES
> font=\footnotesize, text badly centered,
> inside/.style={color=white},]
> % Model name/SAV/IB/CG
> \def\designvalues{0/Microsoft's model/25/65/40,1/Alternative
> model/50/25/20,2/Google's model/60/15/20}
> \def\colwidth{0.4}
> \def\maxy{150}
>
> \draw[->] (0,0) -- (0,\maxy);
> \path (-0.25,\maxy/2) node [left] {Value};
(Continue reading)


Gmane