Python - matplotlib
Python is no doubt one of the most powerful and easy-to-use programming languages nowadays, partly because it comes with a lot of useful and convenient packages. matplotlib is one of the packages that I use very often to produce graphs and figures for my research. While the official Website already provides a fairly comprehensive documentation and a lot of examples, sometimes I still find it difficult to make my graphs and figures look the way I want them to be. Below are some examples that I think would be useful to many other people who use the package.
# Using scientific notation on the axes
# Using scientific notation on the axes
import pylab
pylab.show()
x = [1,2,3,4,5]
y = [10000,20000,30000,40000,50000]
pylab.figure(1, figsize=(4,2))
pylab.plot(x,y)
axes = pylab.gca()
myformatter = pylab.FormatStrFormatter("%.1e")
axes.yaxis.set_major_formatter(myformatter)
pylab.show()
|
|
import pylab
x = [1,2,3,4,5]
y = [10000,20000,30000,40000,50000]
pylab.figure(1, figsize=(4,2))
pylab.plot(x,y)
axes = pylab.gca()
myformatter = pylab.ScalarFormatter(useMathText=True)
myformatter.set_powerlimits((-3,3))
axes.yaxis.set_major_formatter(myformatter)
pylab.show()
|
|