Grid on a Matrixplot
The following code works perfectly up to a little problem. On the result the dotted grid lines are on integer ticks. I would like them to clearly separate the tiles (in greater dimension for the program it becomes unreadable. Is there a way to correct this problem (if not we can display a $(0,1)$ matrix but it is less elegant)
p = MixedIntegerLinearProgram(maximization=False, solver="GLPK")
x = p.new_variable(integer=True, nonnegative=True)
y = p.new_variable(integer=True, nonnegative=True)
p.add_constraint(x[0]+x[1]+x[3]-2*y[0]==1);
p.add_constraint(x[1]+x[0]+x[2]+x[4]-2*y[1]==1);
p.add_constraint(x[2]+x[1]+x[5]-2*y[2]==1);
p.add_constraint(x[3]+x[4]+x[0]+x[6]-2*y[3]==1);
p.add_constraint(x[4]+x[3]+x[5]+x[1]+x[7]-2*y[4]==1);
p.add_constraint(x[5]+x[4]+x[2]+x[8]-2*y[5]==1);
p.add_constraint(x[6]+x[7]+x[3]-2*y[6]==1);
p.add_constraint(x[7]+x[6]+x[8]+x[4]-2*y[7]==1);
p.add_constraint(x[8]+x[7]+x[5]-2*y[8]==1);
p.set_objective(x[0]+x[1]+x[2]+x[3]+x[4]+x[5]+x[6]+x[7]+x[8]);
p.add_constraint(x[0]>=0);
p.add_constraint(x[0]<=1);
p.add_constraint(y[0]>=0);
p.add_constraint(y[0]<=2);
p.add_constraint(x[1]>=0);
p.add_constraint(x[1]<=1);
p.add_constraint(y[1]>=0);
p.add_constraint(y[1]<=2);
p.add_constraint(x[2]>=0);
p.add_constraint(x[2]<=1);
p.add_constraint(y[2]>=0);
p.add_constraint(y[2]<=2);
p.add_constraint(x[3]>=0);
p.add_constraint(x[3]<=1);
p.add_constraint(y[3]>=0);
p.add_constraint(y[3]<=2);
p.add_constraint(x[4]>=0);
p.add_constraint(x[4]<=1);
p.add_constraint(y[4]>=0);
p.add_constraint(y[4]<=2);
p.add_constraint(x[5]>=0);
p.add_constraint(x[5]<=1);
p.add_constraint(y[5]>=0);
p.add_constraint(y[5]<=2);
p.add_constraint(x[6]>=0);
p.add_constraint(x[6]<=1);
p.add_constraint(y[6]>=0);
p.add_constraint(y[6]<=2);
p.add_constraint(x[7]>=0);
p.add_constraint(x[7]<=1);
p.add_constraint(y[7]>=0);
p.add_constraint(y[7]<=2);
p.add_constraint(x[8]>=0);
p.add_constraint(x[8]<=1);
p.add_constraint(y[8]>=0);
p.add_constraint(y[8]<=2);
p.solve()
X=[v[1] for v in sorted(p.get_values(x, convert=ZZ, tolerance=1e-3).items())]
m=3;
n=3;
X1=list(matrix(m,n,X))
X2 = [list(v) for v in X1]
table(X2)
matrix_plot(X1,cmap=["white","black"]).show(gridlines=True,gridlinesstyle={"linestyle": ":", "linewidth": 2, "color": "red"})