Monday, November 18, 2013

I was wrong, matplotlib isn't gnuplot.

Upon review gnuplot, used by octave, just isn't up to the same quality as matplotlib, used by python.  The similarity is due to both trying to easily port code from MatLab.  Here's equivalent python code to the code I produced in "gnuplot, octave, and python":
import numpy as np
import matplotlib.pyplot as plt

plt.figure(1)
plt.clf
x=np.arange(-10.,10.1,0.1)

plt.subplot(2,1,1)
plt.plot(x,np.sin(x))
plt.xlabel('x',fontsize=12)
plt.ylabel('Sin(x)',fontsize=12)
plt.text(-12.3,1,'(1)',fontsize=12)
plt.title('Text Positioning',fontsize=16)

plt.subplot(2,1,2)
plt.plot(x,2 * np.sin(x))
plt.xlabel('x',fontsize=12)
plt.ylabel('2 * Sin(x)',fontsize=12)
plt.text(-12.3,2,'(2)',fontsize=12)
plt.show()

It produces this much nicer plot:
I didn't know about the title function when I did the octave plot.  There is plenty of room for the xlabel on the second subplot.  There are a couple of small differences in behavior and syntax.  The text function seems to position differently, maybe bottom right coordinates in matplotlib as opposed to upper left in gnuplot.
I think this accounts for the xlabel bug in gnuplot.  The same "fontsize" is smaller relative to the plot in matplotlib than in gnuplot.







In addition to syntactic differences there are behavioral differences.  I'm going to have to study matplotlib's event handling.

On a side note... I tried to reproduce the matplotlib histogram example in octave.  I got a stack overflow error when trying to create an array of 10,000 random numbers where numpy had no problem.  Maybe octave has some module I need to add.  Even producing a histogram of 1,000 random numbers took quite a bit of time in octave.  I'm almost ready to buy MatLab again just for the "Computational Neuroscience" course.  I have trouble with trial versions of software because they leave bad things on one's computer to prevent you from just reinstalling it after the trial period has run out.  These things can interfere with normal installation later on.

No comments:

Post a Comment