# Deboxed, axes and labels in a linear programming 3Dgraphic

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 + x + 3*x <= 1)
p.add_constraint(3*x + 2*x + x <= 1)
p.add_constraint(x + 3*x + 2*x <= 1)
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 close merge delete

Sort by » oldest newest most voted

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()
xmax, ymax, zmax = graph.bounding_box()
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).

more

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

> 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.