2.10 Covgrad 2

R figure

Code
ranking <- c(1,1,1,0,1,0,0,1,0,0)
x <- c(0,0,0,0,100,100,200,300,300,400,500)
y <- c(0,100,200,300,300,400,400,400,500,500,500)

h <- 500 
w <- 500 
grid.step <- 50


plot( c(0,w), c(0,h),  
     xaxs = "i",yaxs = "i",
     xaxt = 'n', yaxt = 'n',
     type = "n",
     xlab = "Negatives", ylab = "Positives")
     
axis(2,y,labels=c('','p1','p2','p3','','p4','','','p5','',''))
axis(1,x,labels=c('','','','','n1','','n2','n3','','n4','n5'))

gx <- grid.step
while (gx <= w) {
  abline(v = gx, col="gray", lty="dotted")
  gx <- gx + grid.step
}
gy <- grid.step
while (gy <= h) {
  abline(h = gy, col="gray", lty="dotted")
  gy <- gy + grid.step
}


text( x[4]+10, y[4]-15, "A", col="red")
text( x[6]+10, y[6]-15, "B", col="red")
text( x[9]+10, y[9]-15, "C", col="red")


lines( x, y, lty=1, type='o')

segments(x[4],y[4],x[6],y[6],lty=3,col="red")
segments(x[6],y[6],x[9],y[9],lty=3,col="red")

Python figure

Code
import matplotlib.pyplot as plt

ranking = [1,1,1,0,1,0,0,1,0,0]
x = [0,0,0,0,100,100,200,300,300,400,500]
y = [0,100,200,300,300,400,400,400,500,500,500]

h = 500
w = 500
grid_step = 50

fig, ax = plt.subplots()
ax.set_xlim(0, w)
(0.0, 500.0)
Code
ax.set_ylim(0, h)
(0.0, 500.0)
Code
ax.set_xticks(x)
ax.set_xticklabels(['','','','','n1','','n2','n3','','n4','n5'])
ax.set_yticks(y)
ax.set_yticklabels(['','p1','p2','p3','','p4','','','p5','',''])

for gx in range(grid_step, w + 1, grid_step):
    ax.axvline(x=gx, color='gray', linestyle='dotted')
for gy in range(grid_step, h + 1, grid_step):
    ax.axhline(y=gy, color='gray', linestyle='dotted')

ax.text(x[3]+10, y[3]-15, "A", color="red")
ax.text(x[5]+10, y[5]-15, "B", color="red")
ax.text(x[8]+10, y[8]-15, "C", color="red")

ax.plot(x, y, linestyle='solid', marker='o')
ax.plot([x[3], x[5]], [y[3], y[5]], linestyle='dashed', color="red")
ax.plot([x[5], x[8]], [y[5], y[8]], linestyle='dashed', color="red")

ax.set_xlabel("Negatives")
ax.set_ylabel("Positives")
plt.show()