Skip to content

Instantly share code, notes, and snippets.

@elshize
Created August 8, 2018 16:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save elshize/7edaa8c0d2c3e346081d3b954387cc74 to your computer and use it in GitHub Desktop.
Save elshize/7edaa8c0d2c3e346081d3b954387cc74 to your computer and use it in GitHub Desktop.
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches
import matplotlib.lines as mlines
## All plt.rcParams lines are defined globally for all the following plots.
# Use latex to produce it and use the ACM default sans-serif package
plt.rcParams['text.usetex'] = True
plt.rcParams['text.latex.preamble'] = r'\usepackage{libertine}\usepackage{fixltx2e}'
plt.rcParams['font.family'] = "sans-serif"
# Lines, grids, and colors.
plt.rcParams['axes.linewidth'] = 0.5
plt.rcParams['axes.axisbelow'] = True
plt.rcParams['lines.linewidth'] = 0.5
plt.rcParams['patch.linewidth'] = 0.5
plt.rcParams['axes.grid'] = True
plt.rcParams['grid.alpha'] = 0.5
plt.rcParams['grid.linestyle'] = '-'
plt.rcParams['grid.linewidth'] = 0.2
plt.rcParams['hist.bins'] = 'auto'
plt.rcParams['font.size'] = 8
colors = plt.get_cmap('tab10').colors
plt.plot(x1, y1, '.-', color=colors[0], label='Plot 1', markersize=2)
plt.plot(x2, y2, '.-', color=colors[1], label='Plot 2', markersize=2)
plt.legend()
plt.title('Plot Example', fontsize=9)
plt.xlabel('X axis')
plt.ylabel('Y axis')
# Have to define ticks in order to use the latex font.
xticks = [0, 5, 10, 15, 20]
yticks = [0.08, 0.09, 0.1, 0.11, 0.12]
plt.xticks(xticks, xticks, fontsize=8)
plt.yticks(yticks, yticks, fontsize=8)
fig = plt.gcf()
fig.subplots_adjust(bottom=0.15, left=0.15)
fig.set_size_inches((3.3, 2.5))
plt.savefig('example.pdf')
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment