Thursday, March 14, 2013

Sorting two numpy arrays

Suppose you have two numpy arrays arr1 and arr2 and you want to sort them in such a way that one of them is sorted with the index used to sort the second array. Probably not clear at this point. So, let's just look at an example:

In [1]: arr1 = array([3,1,4,2])
In [2]: arr2 = array([5,3,1,6])
In [3]: ind = lexsort((arr1,arr2))
In [4]: print arr1[ind]
[4 1 3 2]
In [4]: print arr2[ind]
[1 3 5 6]

Doing this, we have sorted the two arrays using the sorting order of the second one. For using sorting order of first array, simply inverse them in lexsort(). Note: in this case, all you're trying to do is getting lexsort() to return the indices of the sorting. So, it doesn't matter what you put as a first array.

Removing axis ticks in Python Matplotlib plots while keeping the axes labels

You can remove the axes in a Matplotlib plot with the command axis('off') but if you want to keep the axes labels, that doesn't work. So, here is a way around it:

ax = subplot(1,1,1) 
xlabel('some label for x') 
ylabel('some label for y')

You can customize your axis ticks and tick labels using set_xticks(), set_yticks(), set_xticklabels() and set_yticklabels(). Check the Maplotlib documentation for more details.

Sunday, March 10, 2013

IPad website layout

Here is a link that helped me when designing a website. The first time I opened my webpage on my iPad, it was really ugly, this helped a great deal.

On a side note, this guy's website is pretty cool: has some neat CSS tricks but also some cool artwork (mostly drawings) and other neat stuff.

Saturday, March 9, 2013

How to use a custom font on an html site

In order to use a custom font on an html site, you can use the CSS feature named @font-face. Note that it may not work on older browsers. See w3schools for details.

Here is how you use it, add these lines in your css file:

@font-face { font-family: myOwnFont; src: url('myOwnFont-Roman.ttf'); } @font-face { font-family: myOwnFont; font-weight: bold; src: url('myOwnFont-Bold.ttf');}

Then, simply call it using font-family:

p {font-family: myOwnFont; } .

Data fitting with SciPy