1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
| import matplotlib.pyplot as plt from matplotlib.collections import EventCollection import numpy as np
np.random.seed(19680801)
xdata = np.random.random([2, 10])
xdata1 = xdata[0, :] xdata2 = xdata[1, :]
xdata1.sort() xdata2.sort()
ydata1 = xdata1 ** 2 ydata2 = 1 - xdata2 ** 3
fig = plt.figure() ax = fig.add_subplot(1, 1, 1) ax.plot(xdata1, ydata1, 'r', xdata2, ydata2, 'b')
xevents1 = EventCollection(xdata1, color=[1, 0, 0], linelength=0.05) xevents2 = EventCollection(xdata2, color=[0, 0, 1], linelength=0.05)
yevents1 = EventCollection(ydata1, color=[1, 0, 0], linelength=0.05, orientation='vertical') yevents2 = EventCollection(ydata2, color=[0, 0, 1], linelength=0.05, orientation='vertical')
ax.add_collection(xevents1) ax.add_collection(xevents2) ax.add_collection(yevents1) ax.add_collection(yevents2)
ax.set_xlim([0, 1]) ax.set_ylim([0, 1])
ax.set_title('line plot with data points')
plt.show()
|