Fork me on GitHub
Vijai Kumar S
A Space to share my views on World, Science and People

How to make publication quality plots using Python

This is one of my strongest suit. I have been using Python based tools a while for producing publication quality graphs. This write up will not focus on teaching anybody plotting because there are lot of good tutorials on matplotlib in youtube and you can find a lot more in places like github. I will try to focus on giving an outline specifically to make publication quality graphs. This requires a lot of head scratching, googling and stack overflowing for arriving at a decent output. I will try to make things easy by giving a few pointers on this topic.

Let us start from a very simple line graph for the sake of simplicity. I will try to plot a simple sine curve using matplotlib without using any tweaks.

import numpy as np  
import matplotlib.pylab as plt  
x = np.linspace(-np.pi,np.pi)  
y = np.sin(x)  
plt.plot(x,y,'k-')  
plt.xlabel('X')  
plt.ylabel('Sin(X)')  
plt.title('Sine Curve')  
plt.ylim(-1.05,1.05)  
plt.grid()  
plt.savefig('sine.png')  

The curve above looks good enough. But it is not something you would want to include in a journal article. Let us spice up the same graph with the help of latex. You would really be surprised with what usetex = True can do for you. The modified code with latex can be seen below.

#Library imports
import numpy as np  
import matplotlib.pylab as plt  
#Latex Backend for Matplotlib
plt.rc('text', usetex=True)  
plt.rc('font', family='serif')  
x = np.linspace(-np.pi,np.pi)  
y = np.sin(x)  
plt.plot(x,y,'k-')  
plt.xlabel(r'\textsc{X}')  
plt.ylabel(r'\textsc{Sin(X)}')  
plt.title(r'\textsc{Sine Curve}')  
plt.ylim(-1.05,1.05)  
plt.grid()  
plt.savefig('sine.png')  

Now that is something you can use in a conference paper or even a journal article and it was made possible by simply rendering the entire figure with a $\rm\LaTeX$ backend. This is just a basic example. The only issue with plotting is that every user has an unique problem and specific requirements. Hence constant tweaking is required for getting a few things just the way you want in matplotlib. Here are a few more sample i made for my personal research purposes. These are a bit more complex than the example shared above. But i am more than willing to share the source code for anyone interested.


P.S. Hotlinking to images will not be tolerated. Using content without request will cause you some trouble. So please don't do that

comments powered by Disqus
subscribe