# How to make publication quality plots using Python

Plotting is one of my strongest suits. 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 a 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 an elementary 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 be surprised by 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 merely rendering the entire figure with a LaTeX backend. This is just a basic example. The only issue with plotting is that every user has a unique problem and specific requirements. Hence constant tweaking is required for getting a few things just the way you want in matplotlib. Here is a few more sample I made for my 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