Ask Your Question
1

Deboxed, axes and labels in a linear programming 3Dgraphic

asked 2019-10-22 06:09:24 -0600

Cyrille gravatar image

updated 2019-10-22 09:02:25 -0600

Whichever be my efforts, I fail to obtain a not boxed graphic with labeled axes. I need help. I want also to have the figure in an appropriate scale and with the edges in black Thanks.

p = MixedIntegerLinearProgram()
x = p.new_variable(real=True)
p.add_constraint(2*x[1] + x[2] + 3*x[3] <= 1)
p.add_constraint(3*x[1] + 2*x[2] + x[3] <= 1)
p.add_constraint(x[1] + 3*x[2] + 2*x[3] <= 1)
p.add_constraint(x[1] >= 0)
p.add_constraint(x[2] >= 0)
p.add_constraint(x[3] >= 0)
my_polyhedron = p.polyhedron()
pol=my_polyhedron.plot(color='blue', alpha=.5)
var("x y z")
plane=implicit_plot3d(x + 2*y + 3*z==1, (x,0,0.5), (y,0,0.25),
(z,0,1), color='yellow', alpha=.25,frame=False)
from sage.plot.plot3d.plot3d import axes
from sage.manifolds.utilities import set_axes_labels
plane+pol+axes(1, color='black', axes_labels=['$x_1$','$x_1$','$x_3$'])
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2019-10-23 08:29:48 -0600

eric_g gravatar image

Unfortunately, the set_axes_labels function from sage.manifolds.utilities uses a convention different from axes, so that the x_2 label is ill-placed. However it is easy to adapt it, from the source code that you get by typing set_axes_labels??. Replace the last two lines of the code snippet of your example by

def set_axes_labels(graph, xlabel, ylabel, zlabel, **kwds):
    from sage.plot.plot3d.shapes2 import text3d
    xmin, ymin, zmin = graph.bounding_box()[0]
    xmax, ymax, zmax = graph.bounding_box()[1]
    dx = xmax - xmin
    dy = ymax - ymin
    dz = zmax - zmin
    x1 = xmin + dx / 2
    y1 = ymin + dy / 2
    z1 = zmin + dz / 2
    xmin1 = xmin - dx / 20
    xmax1 = xmax + dx / 20
    ymin1 = ymin - dy / 20
    zmin1 = zmin - dz / 20
    graph += text3d('  ' + xlabel, (x1, ymin1, zmin1), **kwds)
    graph += text3d('  ' + ylabel, (xmin1, y1, zmin1), **kwds)
    graph += text3d('  ' + zlabel, (xmin1, ymin1, z1), **kwds)
    return graph

plot = plane + pol + axes(1, color='black')
plot = set_axes_labels(plot, 'x_1','x_2','x_3')
plot

You can also replace the last line by

show(plot, viewer='threejs')

in order to use the three.js viewer (to become the default in SageMath 9.0).

edit flag offensive delete link more

Comments

Thanks a lot. But two questions remains : is it possible to have the labels lin latex and to have arrows for the axes

Cyrille gravatar imageCyrille ( 2019-10-24 11:23:19 -0600 )edit

> is it possible to have the labels lin latex

No, unfortunately, this is not possible

>to have arrows for the axes

Yes, this is possible: instead of axes, use the command arrow3d three times. Type arrow3d? for details.

eric_g gravatar imageeric_g ( 2019-10-24 14:35:51 -0600 )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: 2019-10-22 06:09:24 -0600

Seen: 27 times

Last updated: Oct 23