I have the following code to draw some lines in matplotlib. I have tried to make the points be shown with transparent circles rather than the standard solid filled in circles.
How can I make a little gap before and after each circle in the graph so the dashed lines don't touch them. I think this would look better here as I only have data at the points so the lines in between don't represent real data.
import matplotlib.pyplot as plt
import numpy as np
t = np.array([0.19641715476064042,
0.25,
0.34,
0.42])
c = np.array([0.17,
0.21,
0.27,
0.36])
plt.plot(t, '-go', markerfacecolor='w', linestyle= 'dashed', label='n=20')
plt.plot(c, '-bo', markerfacecolor='w', linestyle= 'dashed', label='n=22')
plt.show()
This is what the matplotlib code currently gives me.

This is what I would like it to ultimately look like (clearly with different data).

Beware that you seem to misuse the fmt format string (like "-go") in your calls to plot. In fact for a dashed line fmt should be more something like "--go".
I personally tend to find the use of keyword arguments clearer even if more verbose (in your case, linestyle="dashed" prevails on fmt string)
http://matplotlib.org/api/axes_api.html?highlight=plot#matplotlib.axes.Axes.plot
Anyway, below a tentative to reproduce the desired plot:
import matplotlib.pyplot as plt
import numpy as np
t = np.array([0.19641715476064042,
0.25, 0.34, 0.42])
c = np.array([0.17, 0.21, 0.27, 0.36])
def my_plot(ax, tab, c="g", ls="-", marker="o", ms=6, mfc="w", mec="g", label="",
zorder=2):
"""
tab: array to plot
c: line color (default green)
ls: linestyle (default solid line)
marker: kind of marker
ms: markersize
mfc: marker face color
mec: marker edge color
label: legend label
"""
ax.plot(tab, c=c, ms=0, ls=ls, label=label, zorder=zorder-0.02)
ax.plot(tab, c=c, marker=marker, ms=ms, mec=mec, mfc=mfc, ls="none",
zorder=zorder)
ax.plot(tab, c=c, marker=marker, ms=ms*4, mfc="w", mec="w", ls="none",
zorder=zorder-0.01)
my_plot(plt, t, c="g", mec="g", ls="dashed", label="n=20")
my_plot(plt, c, c="b", mec="b", ls="dashed", label="n=22")
plt.legend(loc=2)
plt.show()

Also consider reading the legend guide in the official documentation: http://matplotlib.org/users/legend_guide.html?highlight=legend%20guide
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With