Home > Mobile >  How do I render the dots completely while keeping all the grid lines?
How do I render the dots completely while keeping all the grid lines?

Time:10-08

I'm trying to reproduce the figure from page 405 of "Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest and Clifford Stein. Introduction to Algorithms, 3rd Edition. The MIT Press, 2009"

enter image description here

Here is the code

plt.plot(0,6,'o',c='k')
plt.plot(1,0,'o',c='k')
plt.plot((0,1),(6,0))
plt.xlim([0, 9])
plt.ylim([0, 7])
plt.grid()

which renders the dots incompletely

enter image description here

In contrast, the following code renders the dots completely though, the grid lines at x=1, 3, disappears

enter image description here

How do I render the dots completely while keeping all the grid lines?

CodePudding user response:

Using enter image description here

The entire figure:

fig, ax = plt.subplots()
x = [0, 1, 6, 8, 7, 5, 2]
y = [6, 0, 1, 2, 5, 4, 3]
ax.fill(x, y, fill=False)
ax.scatter(x, y, c='k')
ax.set_xlim([-1, 9])
ax.set_ylim([-1, 7])
ax.yaxis.set_major_locator(MultipleLocator(1))
ax.xaxis.set_major_locator(MultipleLocator(1))
ax.grid()
ax.set_axisbelow(True)

enter image description here

EDIT: Based on your (since-deleted) enter image description here

  • Related