Ask Your Question
0

Grid on a Matrixplot

asked 2024-04-09 11:44:52 +0100

Cyrille gravatar image

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"})
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2024-04-10 06:02:46 +0100

dsejas gravatar image

Hello, @Cyrille! I am not 100% if the following is what you want, but I am posting it as an answer because the permalink does not fit in a comment. Please, take a look at this code. If this is what you want, please let me know, so I can elaborate this as a proper answer.

edit flag offensive delete link more

Comments

All is fine. Thanks Dsejas

Cyrille gravatar imageCyrille ( 2024-04-18 10:49:24 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2024-04-09 11:44:52 +0100

Seen: 141 times

Last updated: Apr 10