Archive for April, 2011

Vertical labels on gnuplot LaTeX graphs

Thursday, April 28th, 2011

This post exists because doing this was far harder than it should have been and hopefully this will help someone else in the future.

When creating a bar chart/histogram in gnuplot using the latex driver if there are a lot of bars and the labels for the bars are over a certain length then the labels overlap horribly. The solution to this would be to rotate them and the following LaTeX and gnuplot code allows that to happen and deals with various fallout that results.

The following defines a length for storing offsets of the labels in \verticallabeloffset as this offset will depend on the length of the text. It also stores a length which holds the maximum of those values \maxverticallabeloffset. It provides a command \verticallabel which does hte following: calculates the length of the label, moves the start position across by 1.4em, moves the label down by 2em (to provide space for the x axis label) and then down by the length of the text. It then uses a sideways environment to make the text vertical. Then it uses the ifthen package to work out if the \verticallabeloffset is bigger than any previously seen and if so it sets \globaldefs=1 so that the effect of the \setlength command will be global rather than being restricted to the local scope and then sets it back to 0 (this is a nasty hack).
It also provides the \xaxislabel command which shifts the x axis title up into the space between the x axis and the labels.

\providecommand{\verticallabel}[1]{\settowidth{\verticallabeloffset}{#1}\hspace{1.4em}\vspace{-2em}\vspace{-\verticallabeloffset}\begin{sideways} #1 \end{sideways}\ifthenelse{\lengthtest{\verticallabeloffset>\maxverticallabeloffset}}{\globaldefs=1\setlength\maxverticallabeloffset{\verticallabeloffset}\globaldefs=0}{}}

Having defined that the following allows gnuplot histograms generated with the LaTeX driver to be included in a LaTeX document. It first resets the maximum offset and then ensures there is sufficient space for the labels

\caption{foo bar chart}

The following gnuplot code generates a histogram which uses this to get the labels to display correctly.

set terminal latex size 16cm, 7.5cm
set style histogram errorbars

set ylabel "\\begin\{sideways\}Mean absolute error\\end\{sideways\}"
set xlabel "\\xaxislabel\{Data set\}"

set output "comparisonSummary_data.tex"
plot "comparisonSummary.dat" index 0 using 2:($3*1.96):xtic("\\verticallabel\{" . stringcolumn(1) . "\}") with histogram title "Mean absolute error for different data sets"

I hope this helps someone. I should get around to actually patching the gnuplot latex driver so that it works properly – but that will have to wait until post exams.

Voting no to AV is just stupid

Friday, April 22nd, 2011

So that might seem a little insulting but it is a statement of fact rather than of opinion. A few days I thought that AV was simply better than FPTP and so “yes” was obviously the right answer. Further discussion and consideration of the issue moved me to the position that since there were no valid arguments at all in favour of FPTP over AV based on methodology (it is simply better in all respects) anyone voting no was either being stupid (believing the deliberate lies being spread by the no campaign) or immoral (voting no in the belief that by supporting an inferior more unfair voting system they were helping to rig elections in favour of their preferred party). Further consideration has led me to believe that even the immoral argument is invalid and so no one who has carefully thought out the issues can vote no.

Before I can explain why you will first need to have any questions you have about methodology addressed. Is AV actually always better than FPTP? Well yes and Tim Gowers (Cambridge maths professor) has written a rather good blog post about AV vs FPTP which has been getting a lot of mileage among the Cambridge students. Having read that and perhaps thought a little about it you will hopefully come to the conclusion that the only reasons you have left for voting no are the ones that I would call immoral – you want to rig the vote in favour of your party because it is easier to rig the vote so that they win with a minority than to actually persuade people that their policies are better than those of the other parties.

Actually those arguments are just stupid as well, at least in the long term – current MPs can perhaps vote no on the understanding that they are only being immoral and not stupid but for the voter that expects to be around (or care about) elections in 20 or more years time then the short term thinking which results in a no vote being a valid option for immoral reasons is no longer valid.

At this point some people might be thinking “Your a lefty I don’t believe anything you say”[0] to which I will make some Peterhouse specific comments: Nicholas Wilson, Nick Dixon-Clegg, Matthew Wells are Conservatives through and through, and are voting YES to AV because it is fair. Owen Woods is a Socialist and is voting YES to AV because it is better. I as a green/orange lefty kind of person who respects people on the right enough that there are even a couple of people in the Conservative party I would vote for am voting YES to AV because it is fairer and better and there is no other sensible option on the table. This campaign is not a party political one it is a campaign between those who are right and those who are afraid of change even for the better.

Consider the two cases where someone might be intending to vote no based on immoral reasons: they are either a Labour or a Conservative voter and think that AV might harm the chances of their party getting into power so often. Well if you are a Labour voter then as Tim Gowers so eloquently puts it “A LABOUR SUPPORTER VOTING FOR FPTP IS A TURKEY VOTING FOR CHRISTMAS”. However what of the Conservative voter?

Well first I will assume that whichever party you support you think that they are the best party, they have the best policies the best principles and are generally better than all the other choices. (If not why on earth are your supporting them.) Then since they are the best then surely eventually they should win under a fair voting system as it will be clear that their policies and principles are better when discussed rationally, over time historically it will become clear (or be possible to make clear) that if the policies of your favoured party had been adopted on a whole range of issues at a whole range of different points in time then the outcome would have been unequivocally better. What I am saying here is that under a fair system democracy should eventually produce the right result if you are correct in your assertion that your favoured party is the best one. It might take a long time, it won’t be easy and things are dynamic so who the best party is in your eyes might change as its current leadership retire and are replaced – but if you believe in democracy then hopefully you believe that given enough time and effort on the side of the best party then they win. (Perhaps I am assuming more faith in democracy than you have, hopefully you have enough that the rest of the argument follows anyway)

Currently the Conservatives might do better under FPTP than under AV in a (fairly small) number of constituencies because though the majority of people in that constituency don’t want them to win they are split between Labour and Lib Dems as to who they prefer first over the Conservatives though the majority would sill prefer Labour over the Conservatives and Lib Dems over the Conservatives. This is the general problem of split voting and is one of the places that FPTP fails really hard because it does not collect enough information from voters to be able to pick the candidate with the most support since FPTP is designed for and works perfectly fine in situations where there are only 2 candidates and fails utterly when there are more than 2 (and there are always more than 2 candidates in constituency elections – even in the speaker’s seat).
However when picking a voting system we are picking something for the long term, we have had FPTP for over 100 years and Australia has had AV for over 100 years. It is not something that we change all that often and so any time the question does have a chance to be decided it needs to be treated seriously with application of long term thinking.
Currently there is not much of a split on the right while there is a fairly large spit on the left, but who can say for sure that in 20, 50 or 100 years from now the situation might be the other way around. For example UKIP might gain support from Conservative party voters, the Lib Dems might move further right (they are currently in coalition with the Conservatives after all) and so pull voters away from the Conservative party resulting in a split vote on the right while Labour mops up everyone left of centre. Then we could have a situation where Labour gained power and were immovable from it for decades despite having only minority support while parties on the right fought over who was the true party of the right. A Conservative voter might hope that Conservative voters are too sensible to let that happen and perhaps they are right but no one can guarantee that.

So we get to make a choice on the voting system now, and we probably won’t get a chance like this again for a long time. While in the short term it might favour particular parties a little to remain with FPTP, AV is clearly better and no one can know the future well enough to be sure that voting no now won’t result in the party they hate jumping up and down laughing on them for decades with a minority of the vote.

Vote AV unless you are stupid, but then even stupid people should be able to understand simple logical arguments ;-)

[0]: Words to that effect were said to me yesterday fortunately there were some Conservatives around to do the persuading.

P.S. though perhaps you might have found this insulting I don’t make any apologies for that, however it doesn’t mean I don’t still like you as a person, I just think you are provably wrong or a little immoral.