Skip to content

Instantly share code, notes, and snippets.

@mehdirezaie
Last active April 10, 2021 00:55
Show Gist options
  • Save mehdirezaie/aac1d9f4a4c8998d9608d482baccac70 to your computer and use it in GitHub Desktop.
Save mehdirezaie/aac1d9f4a4c8998d9608d482baccac70 to your computer and use it in GitHub Desktop.
Publication quality

Publication Quality with Python

import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt

mpl.rcParams['font.family'] = 'Liberation Sans Narrow'
plt.rcParams['font.size'] = 18
plt.rcParams['axes.linewidth'] = 2  

# create figure and add an axes object
fig = plt.figure(figsize=(6, 4))
ax = fig.add_axes([0, 0, 1, 1])

# set x and y axes labels
ax.set_xlabel('Wavelength [nm]', labelpad=10)
ax.set_ylabel(r'Power Spectrum [nm$^{2}$]', labelpad=10)

# set spines off
#ax.spines['right'].set_visible(False)
#ax.spines['top'].set_visible(False)

# major and minor ticks of the x and y axes
axis_kw = dict(width=2, direction='in', pad=5)
ax.xaxis.set_tick_params(which='major', size=9, top=True, **axis_kw)
ax.xaxis.set_tick_params(which='minor', size=6, top=True, **axis_kw)
ax.yaxis.set_tick_params(which='major', size=9, right=True, **axis_kw)
ax.yaxis.set_tick_params(which='minor', size=6, right=True, **axis_kw)

# major and minor tick locations
ax.xaxis.set_major_locator(mpl.ticker.MultipleLocator(1.0))
ax.xaxis.set_minor_locator(mpl.ticker.MultipleLocator(0.25))
ax.yaxis.set_major_locator(mpl.ticker.MultipleLocator(0.4))
ax.yaxis.set_minor_locator(mpl.ticker.MultipleLocator(0.1))

# grid
# ax.grid(ls=':', alpha=0.5, which='both') 

# data
x = np.linspace(0., 10., 100)
ax.plot(x, np.sin(x), color='k', lw=2)
ax.plot(x, np.cos(x), color='k', lw=2, ls='--')

Then you will get
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment