Wednesday, October 20, 2010

Plotting using Matplotlib

Share axis between two subplots

In order to share the x-axis between two subplot:

import pylab as p
fig = p.figure()
ax1 = fig.add_subplot(211)
ax2 = fig.add_subplot(212, sharex=ax1)


Plotting the lines before the points
In a plot with several sets of points and lines connecting each set, in order to plot the points on top of the lines (so that the line doesn't show inside the point) use:

R=range(1,10)
P=range(1,10)
p.plot(R,P,color='0.2',lw=1.5, zorder=1)
p.scatter(R,P,s=150,color=c, zorder=2)

Wednesday, October 6, 2010

Encrypt and decrypt files with a password in Linux

There are various ways to make a file password protected. Use one of the following commands to encrypt or decrypt files with a password.

  1. Use GNU gpg command
  2. Use mcrypt command
  3. Use openssl command

gpg Command

To encrypt and decrypt files with a password, use gpg command.

To encrypt single file:
gpg -c filename

This will ask for the pass-phrase and will create filename.gpg.

To decrypt file use gpg command:
gpg filename.gpg

To decrypt a file and write output to file output.txt you can run command:
gpg filename.gpg –o output.txt

Friday, October 1, 2010

Matlab plotting tips

Put two legends in one figure

In matlab it is difficult to put two legends in one figure. However, there are several tricks to get this done. One of them is as follows,


% Plot with 9 curves
ph=plot(rand(20,9));
set(gca,'ylim',[-2,5]);

% Label curves 1 and 5
legend(ph(1),'trace one');

% Add and invisible axes
ah=axes('position',get(gca,'position'),'visible','off');

% Add new legend
legend(ah,ph(5),'trace five','location','west');


Cycle through markers in plot loop

If you are plotting in a loop, and want each loop to use a different plot
marker, then


% Define the markers
markers = '.ox+*sdv^<>ph

% The dataset
y=rand(10);
x=[1:10];

% The Loop for plots
for i=1:10,

% Select marker if there are more data than the markers
marker=markers(rem(i,length(markers))+1)

% Plot
plot(x,y(:,i),marker)
hold on
end