Skip to content

Instantly share code, notes, and snippets.

@sdwebb
Last active May 16, 2020 02:07
Show Gist options
  • Save sdwebb/0984f9363f22b0e3fb6cc5867c968ba9 to your computer and use it in GitHub Desktop.
Save sdwebb/0984f9363f22b0e3fb6cc5867c968ba9 to your computer and use it in GitHub Desktop.
A Tufte style dot-dash plot
from matplotlib import pyplot as plt
from matplotlib.ticker import FixedLocator
import matplotlib.font_manager as fm
from matplotlib import pyplot as plt
font = fm.FontProperties(
family = 'Gill Sans',
fname = '/usr/share/fonts/truetype/adf/GilliusADF-Regular.otf')
import matplotlib.pylab as pylab
params = {'axes.spines.right' : False,
'axes.spines.left' : False,
'axes.spines.top' : False,
'axes.spines.bottom' : False,
'font.family' : 'Gill Sans'}
pylab.rcParams.update(params)
import numpy as np
#
# A working example
#
x = np.random.random(100)
y = np.exp(-2.*x + np.random.normal(loc=1., scale=.1, size=100))
fig, ax = plt.subplots()
ax.scatter(x, y, s=5, c='k')
ax.xaxis.set_minor_locator(FixedLocator(x))
ax.yaxis.set_minor_locator(FixedLocator(y))
ax.set_xlabel(r'$x$')
ax.set_ylabel(r'$y$')
@sdwebb
Copy link
Author

sdwebb commented May 16, 2020

Here is an example of how to create an Edward Tufte style dot-dash scatter plot using matplotlib. I think the axis label font size is too small, but that's easy to fix by adding to the params dictionary and this is meant to be a minimum working example. Here is the final output:
dot-dash-plot

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