ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 09 Apr 2024 11:44:52 +0200Grid on a Matrixplothttps://ask.sagemath.org/question/76860/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"})
CyrilleTue, 09 Apr 2024 11:44:52 +0200https://ask.sagemath.org/question/76860/Resizing the table font to fit into the pagehttps://ask.sagemath.org/question/76551/resizing-the-table-font-to-fit-into-the-page/ This table
h_r=["Environnement","Transports","Sécurité","Santé","Sports-et-loisirs","Culture","Enseignement","Commerces","Qualité de vie"]
h_q=["","$\\textbf{Antony}$","$\\textbf{Aix les Bains}$","$\\textbf{Sceaux}$","$\\textbf{Maison-Laffite}$","$\\textbf{Saint-Gratien}$"]
Q=[[8.11,4,7.88,7.83,8.49,8.37,8.03,8.36,7.97,8.46],
[8.73,6.81,7.64,7.93,8.87,7.66,7.43,7.5,8.66],
[8.68,7.1,7.6,7.48,7.91,8.02,8.89,7.85,8.46],
[8.65,7.46,8.45,6.73,8.46,7.55,7.48,7.68,8.51],
[8.13,7.68,7.46,7.38,8.23,7.93,7.7,7.97,8.52]]
QQ=[[round(x,4) for x in Q[i]] for i in range(len(Q))]
T=table(QQ,header_row=h_r,header_column=h_q,align='center')
T
is nice looking but it will be better with a smaller font to fit in the page. Is this request possible ?CyrilleSun, 17 Mar 2024 11:54:44 +0100https://ask.sagemath.org/question/76551/Is it possible to color a string in a list ?https://ask.sagemath.org/question/76505/is-it-possible-to-color-a-string-in-a-list/is there a way to color a string inside a list say
L = ["1","2","3"]
and I want to display 2 in red
CyrilleFri, 15 Mar 2024 10:20:50 +0100https://ask.sagemath.org/question/76505/display square of derivative in LaTeX needs parenthesishttps://ask.sagemath.org/question/73948/display-square-of-derivative-in-latex-needs-parenthesis/Using %display latex
diff(x,t)^2 is displayed in LaTeX as
\frac{\partial}{\partial t}x^2
This is confusing when looking at the LaTeX output. It should have an extra set of parenthesis
(\frac{\partial}{\partial t}x)^2
Is there a way to get this to display correctly, or to use \frac{\partial x}{\partial t}?
QMeqGRThu, 19 Oct 2023 17:33:57 +0200https://ask.sagemath.org/question/73948/Displaying a matrix with scalar fieldshttps://ask.sagemath.org/question/71455/displaying-a-matrix-with-scalar-fields/I have some scalar fields and a matrix whose elements are these scalar fields. A sample code is the following:
reset()
M=Manifold(4, 'M', r'\mathcal{M}')
BL.<t,r,th,ph> = M.chart(r't r:(0,+oo) th:(0,pi):\theta ph:(0,2*pi):\phi')
f=M.scalar_field(function('f')(*BL))
g=M.scalar_field(function('g')(*BL))
h=M.scalar_field(function('h')(*BL))
h=0
mymatrix=matrix([[f+g,g,h],[f,h,g],[h,g,f]])
`f`, `g`, or `h` can be zero or nonzero (according to some calculations).
When I try to display my matrix with `show(mymatrix)` or `print(mymatrix)`, I see `Scalar field on the 4-dimensional differentiable manifold M` instead of the non-zero elements.
What should I do to display my matrix as
[f+g g 0]
[f 0 g]
[0 g f]
preferably without using loops, etc?
tolgaWed, 02 Aug 2023 13:12:05 +0200https://ask.sagemath.org/question/71455/sagemath displays in different lineshttps://ask.sagemath.org/question/65020/sagemath-displays-in-different-lines/ Hi there,
I am trying to display two different things at once. The first is some Latex stuff, and the second is the solution to a symbolic integration done in sage. Here is the code:
eq2 = x*eq0
display(LatexExpr(r'\langle x \rangle = \int\limits_{-\infty}^\infty x\rho dx'))
x1 = eq2.rhs().integral(x, -infinity, infinity)
display(LatexExpr(r'\langle x\rangle = '), x1)
(sorry I don't know how to show my code in a better format)
so what happens is, that the latex expression is displayed in the first line and x1 is displayed in the second line.
I hope someone can help me with this.
P.S.: is there a way to display the integral itself and not only the solution? I avoided this problem by just writing the latex expression manually in the first line. Thanks in advance for your help :)FlopsiturtleWed, 23 Nov 2022 21:20:39 +0100https://ask.sagemath.org/question/65020/Displaying tan instead of sin / coshttps://ask.sagemath.org/question/62899/displaying-tan-instead-of-sin-cos/Newbie question. How do I get SageMath to use tan in its result instead of the ratio and sin and cos?
Example:
sage: a = sin(x^2 + x + 1) / cos(x^2 + x + 1)
sage: a
sin(x^2 + x + 1)/cos(x^2 + x + 1)
I would hope to see instead:
tan(x^2 + x + 1)
Thanks, Ericmn124700Mon, 20 Jun 2022 18:09:18 +0200https://ask.sagemath.org/question/62899/different display methods give different resultshttps://ask.sagemath.org/question/62506/different-display-methods-give-different-results/ when evaluating the following code we get 2 different results even tho the same expressions are being evaluated:
%display plain
k,n = var('k,n')
s = n/2 * sum(3/(n+k)^2, k, 1, n)
s.limit(n=Infinity)
%display unicode_art
k,n = var('k,n')
s = n/2 * sum(3/(n+k)^2, k, 1, n)
s.limit(n=Infinity)
whats going on here? why the inconsistency?
mahmoodWed, 18 May 2022 22:00:15 +0200https://ask.sagemath.org/question/62506/vector_field.apply_map before and after vector.display (weird behaviour)https://ask.sagemath.org/question/55611/vector_fieldapply_map-before-and-after-vectordisplay-weird-behaviour/Hello,
Recently, I have come a cross a very weird behaviour with vector_field.apply_map function. Here is the case:
Consider the following code:
E.<r,th,ph>=EuclideanSpace(coordinates="spherical",start_index=0)
cart.<x,y,z>=E.cartesian_coordinates()
cartf=E.cartesian_frame()
spherf=E.spherical_frame()
E.set_default_frame(cartf)
Now, if I create a vector field, substitute ph with ph_1 and th with th_1, and then display the resultant vector as
var("r_1 th_1 ph_1")
v=E.vector_field([r_1,0,0], frame=spherf, chart=cart);
v.apply_map(lambda c:c.subs(ph==ph_1, th==th_1));show(v.display())
I get **0** printed
However,
If I do the same, but this time if I add **show(v.display())** before calling apply_map function as
var("r_1 th_1 ph_1")
v=E.vector_field([r_1,0,0], frame=spherf, chart=cart); show(v.display())
v.apply_map(lambda c:c.subs(ph==ph_1, th==th_1));show(v.display())
I get
r_1 cos(ph)sin(th) e_x + r_1 sin(ph)sin(th) e_y + r_1 cos(th) e_z
r_1 cos(ph_1)sin(th_1) e_x + r_1 sin(ph_1)sin(th_1) e_y + r_1 cos(th_1) e_z
printed (as expected).
Why does the display function affect the substitution?curios_mindSun, 07 Feb 2021 04:27:55 +0100https://ask.sagemath.org/question/55611/Displaying all symbolic expression with ExpressionNicehttps://ask.sagemath.org/question/55539/displaying-all-symbolic-expression-with-expressionnice/Hi,
Is there a way of turning [ExpressionNice](https://doc.sagemath.org/html/en/reference/manifolds/sage/manifolds/utilities.html#sage.manifolds.utilities.ExpressionNice) the default way of displaying all my symbolic expression?
Instead of importing and calling it like in
from sage.manifolds.utilities import ExpressionNice
var('y')
f = function('f')(x, y)
fun = f.diff(x,x,y,y,x)*x
ExpressionNice(fun)cav_rtMon, 01 Feb 2021 20:46:10 +0100https://ask.sagemath.org/question/55539/Lost %display latexhttps://ask.sagemath.org/question/55034/lost-display-latex/I somehow set display as something so that %display latex no longer works even after restarting the kernel, and Nothing shows up, so I have to use %display plain. I set display to SVG in a submenu thinking I could then export the image but can't set it back since the menu isn't available with a empty result. Can someone tell me what I mis-set and how to reset it? Thanks.cybervigilanteFri, 01 Jan 2021 03:42:28 +0100https://ask.sagemath.org/question/55034/Eliminate truncated graph display with large verticeshttps://ask.sagemath.org/question/54292/eliminate-truncated-graph-display-with-large-vertices/ When I increase the vertex size (to allow more room for labels) on Graph plots, the boundary vertices are trimmed. Here's an example:
Kms = [(3, 4, 2), (3, 7, 5)]
T = Graph()
T.add_edges(Kms)
T.show(layout='tree',tree_root=3,tree_orientation='down',figsize=(2,1.5))
T.show(layout='tree',tree_root=3,tree_orientation='down',figsize=(2,1.5),vertex_size=800)
![image description](https://snipboard.io/pmFx56.jpg)
Changing `figsize` does not solve the problem. How do increase the trim limits so that everything drawn is shown?holistoneThu, 19 Nov 2020 06:04:49 +0100https://ask.sagemath.org/question/54292/Centering a resulthttps://ask.sagemath.org/question/53828/centering-a-result/A simple question. I construct the table `t` (see the following code), and I want the table displayed centered in the cell.
I do not know how since I use Sagecell. I wonder if through `html` display, there is a way to achieve this.
A=matrix(QQ,[[(1/2),(1/4),0],[1,3,-1], [1,1,0]])
b = vector(QQ,[100, 200, 300])
c = vector(QQ,[40, 50, 60])
I=identity_matrix(3)
L=block_matrix([[A,I]],subdivide=False)
L=L.augment(b)
n=A.nrows()
z1=vector([0 for i in range(n+1)])
c=flatten(-c)
z1=flatten(z1)
zc=vector(c+z1)
L=matrix(L.rows()+[zc])
rows = list(L)
t = table(rows, header_row=['$x_1$', '$x_2$','$x_3$','$\\epsilon_1$','$\\epsilon_2$','$\\epsilon_3$','$b$'], header_column=['','$\\epsilon_1$','$\\epsilon_2$','$\\epsilon_3$','z'], frame=True)
show(LatexExpr(r"\text{Le tableau initial du simplex (ou premier dictionnaire) est :}"))
show(t)
I encounter the same problem for displaying plots.CyrilleSun, 11 Oct 2020 09:16:15 +0200https://ask.sagemath.org/question/53828/Displaying result problemhttps://ask.sagemath.org/question/53208/displaying-result-problem/The results of the following code is perfectly displayed in QSagemath server but not in v 9.1 under windows 10
%display latex
A=[0.8,0.44],[0.05,0.1],[0.1,0.36]
b=(24000,2000,6000)
c=(108.21,72.522)
P=InteractiveLPProblemStandardForm(A,b,c,["x_1","x_2"],slack_variables=["e_3","e_4","e_5"])
P = P.standard_form()
P.run_simplex_method()
P = P.standard_form()
P.run_simplex_method()CyrilleFri, 28 Aug 2020 17:20:43 +0200https://ask.sagemath.org/question/53208/Extended LatexExprhttps://ask.sagemath.org/question/51724/extended-latexexpr/ With this command `show(LatexExpr(r"text~:~}")+latex(something))]))`, I can mixed text and result. But in the same sentence I would like to have text+result+text+result. Is it possible ?CyrilleWed, 03 Jun 2020 17:13:32 +0200https://ask.sagemath.org/question/51724/Add a text in Latex in front of a resulthttps://ask.sagemath.org/question/47978/add-a-text-in-latex-in-front-of-a-result/%display latex
var('A, x, y, l, alpha, beta, R, p_x, p_y');
U= A*x^(alpha)*y^(beta);
show(U)
this print U. But I would like to see "U(x) = ..." in a larger font that the standard one which is too small printed on a large device. More generaly , I would like to print some sentences before to disply a resultCyrilleThu, 19 Sep 2019 19:31:46 +0200https://ask.sagemath.org/question/47978/Unicode art as the default printinghttps://ask.sagemath.org/question/50903/unicode-art-as-the-default-printing/I installed Sagemath versio 9.0 using conda and and I'm trying to improve the display style. Right now the display style is something like:
sage: x^2
x^2
In a previous computer I used to get pretty printing by default in Sage. I can reproduce the behavior using `unicode_art`:
sage: unicode_art(z^2)
2
z
But I'd like this to be the default behavior. I know this must be simple but I cannot find that on the docs (probably because I'm searching using the wrong terms or something).
tomchoWed, 22 Apr 2020 03:50:21 +0200https://ask.sagemath.org/question/50903/coexistence of two real_part functionshttps://ask.sagemath.org/question/48266/coexistence-of-two-real_part-functions/In Sage 8.8, this code:
assume(x, 'complex')
print real_part(x)
print real_part(x).simplify()
prints:
real_part(x)
realpart(x)
This does not change any computation (Sage can prove both are equal), but is annoying, since the second one cannot be copy-pasted back into the code. The problem is even more visible when ``%display latex`` is enabled.
Is this a bug? Is there a workaround that makes it possible to display beautiful real parts after a simplification?Florentin JaffredoThu, 10 Oct 2019 23:11:56 +0200https://ask.sagemath.org/question/48266/displaying png in sage-8.1.ova VirtualBox notebookhttps://ask.sagemath.org/question/45732/displaying-png-in-sage-81ova-virtualbox-notebook/Hi
As I encountered freeze and slowdown issues with the W10 upgrade version 1809 and the version generated by SageMath-8.6-Installer-v0.4.1.exe for W10, I got back to my sage-8.1.ova version with VirtualBox.
but when I execute the code below, nothing happens !, no error message either. And the image does not appear.
#P375example7_6PI.ipynb
############################
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import numpy as np
from matplotlib.pyplot import figure
figure(num=None, figsize=(20, 10), dpi=100, facecolor='w', edgecolor='k')
#imgPath="C:\\Users\\jean-pierre\\Documents\\SageMath\\IPYNB\\"
imgPath="/home/sage/Documents/"
img = mpimg.imread(imgPath+"p375Ex7_6.png")
#img = mpimg.imread("p375Ex7_6.png")
imgplot = plt.imshow(img)
![image description](/upfiles/15521212287455305.jpg)ortolljSat, 09 Mar 2019 09:49:43 +0100https://ask.sagemath.org/question/45732/can i display only two decimals of precisionhttps://ask.sagemath.org/question/45222/can-i-display-only-two-decimals-of-precision/I have some lists I want to display. I don't want to limit the precision for the arithmetic that created them, I only want to limit the number of decimal places (not significant figures) that are displayed.
def f(n): return sorted([ 2*cos(2*3.14159*j/n) for j in range(n) ]) ;
f(5)
Gives me the five required values displayed with what seems to be 14 digits after the decimal.
Is it possible to change 14 to some other value?mike newmanTue, 29 Jan 2019 01:15:51 +0100https://ask.sagemath.org/question/45222/show(LatexExpr(" \frac{x}{\cos(x)}")) need 2 \\https://ask.sagemath.org/question/43800/showlatexexpr-fracxcosx-need-2/Hi
to be displayed ok , i need to double anti-slash
is it normal ?
show(LatexExpr(" \\frac{x}{\cos(x)}"))
Sorry I forgot to precise !:
notebook jupyter , Sagemath 8.3 in W10 OS.ortolljMon, 01 Oct 2018 09:59:43 +0200https://ask.sagemath.org/question/43800/values or names on tree branches (graph)https://ask.sagemath.org/question/43691/values-or-names-on-tree-branches-graph/ Hi
How can I make appear names (or,and) numerical values on the branches ?.
#https://ask.sagemath.org/question/43106/preserving-the-rooted-tree-layout-in-graphs/
G=Graph({1:[2,3],2:[4,5],3:[6,7]})
G.weighted(False)
G.show(layout='tree',tree_root=1)
show(G.vertices())ortolljTue, 18 Sep 2018 13:33:09 +0200https://ask.sagemath.org/question/43691/How to force a matrix display accordingly?https://ask.sagemath.org/question/42874/how-to-force-a-matrix-display-accordingly/I am working with matrix groups in small and large dimensions (>20 or >100). Is there a way to fleece sage to make a matrix display as “ d x d matrix over <Ring>” where d>20? It does not do this for any matrix groups like Coxeter/Affine/Weyl/Braid TL Rep. etc.
CoxeterGroup([‘A20’]).gens()[0]
“21 x 21 matrix over Integer Ring”ChernoxylTue, 10 Jul 2018 00:55:28 +0200https://ask.sagemath.org/question/42874/How can I display a plot from a script?https://ask.sagemath.org/question/37719/how-can-i-display-a-plot-from-a-script/If I type
plot(x^2, (x,-2,2))
in sage, I get the expected plot, displayed as a png file by my default image viewer. If instead I put the line
plot(x^2, (x,-2,2)).show()
in a file test.sage and run
sage test.sage
from the command line, I get
Graphics object consisting of 1 graphics primitive
typed on the command line, but no displayed plot.
How do I display a plot from a script?
millermjSat, 27 May 2017 20:37:44 +0200https://ask.sagemath.org/question/37719/How to not print equations and numbers on a single linehttps://ask.sagemath.org/question/36551/how-to-not-print-equations-and-numbers-on-a-single-line/My question is the inverse to [this one](https://ask.sagemath.org/question/36183/how-to-print-equations-and-numbers-on-a-single-line/). Since yesterday I have been unable to print to more than one line in the sage cloud. This is particularly annoying with matrices as the output is now squeezed into one line as in [this picture.](http://imgur.com/a/r2mV0) Line breaks '\n' are ignored entirely. There seems to be nothing that will force printing to a second line, other than word wrap.
I've tested this on several computers and browsers and it is the same each time. Is it a display setting that was somehow activated on my sage cloud account? user101214Fri, 10 Feb 2017 21:08:37 +0100https://ask.sagemath.org/question/36551/Piecewise function of several variables and how to display ithttps://ask.sagemath.org/question/31087/piecewise-function-of-several-variables-and-how-to-display-it/Hi,
I need to define a piecewise function of several variables. For a function of one variable I would use probably `Piecewise`. I would like to work with a function G of two variables t and s that is of this form:
def G(t,s):
if (t < s):
return 1
else:
return 0
Although this works, I would like to have a nice displaying of this function, like a function generated by `Piecewise` does. Is there another way how to define this function?
janThu, 26 Nov 2015 14:32:15 +0100https://ask.sagemath.org/question/31087/How do i display a derivative using view()https://ask.sagemath.org/question/29671/how-do-i-display-a-derivative-using-view/ I can currently display the form of an integral in latex using:
f(x) = x + x^2
view( integral(f(x),x, hold=True) ) #displays the form of the derivative
But i can't figure out how to do it for a derivative:
f(x) = x + x^2
view( derivative(f(x),x, hold=True) ) #fails
view( derivative(f(x),x) ) # takes derivative then displays answer instead of the problem
Is their any easy way to do this? If not, whats the recommended way to fake it (inline latex etc)?gsonnenfFri, 02 Oct 2015 10:17:12 +0200https://ask.sagemath.org/question/29671/Sage 6.7 unusable on high res displayhttps://ask.sagemath.org/question/27147/sage-67-unusable-on-high-res-display/ Installed Sage 6.7 on a new Windows 8.1 Notebook with a 3200x1536 pixel display. All works fine, but Sage is unusable because the fonts are way too small. It seem that VirtualBox is hardwired to assume 72dpi displays and scales accordingly. Is there a way to override this?
During the boot sequence, a CentOS screen is shown briefly. Is there a way to get into the guest OS to edit the X11 config files in /etc/X11/... ? I don't really want to go there, but I could not find any way to fix this so far.
I'm sorry for the mundane nature of this question, but it is a show-stopper for me.
Kind regards,
-- AndreasCedric_NWed, 17 Jun 2015 19:13:35 +0200https://ask.sagemath.org/question/27147/Displaying a numpy plothttps://ask.sagemath.org/question/26122/displaying-a-numpy-plot/ import matplotlib
import numpy as np
import matplotlib.pyplot as plt
plt.figure(figsize=(6, 3))
plt.plot(x, y)
plt.show()
Why doesn't `plt.show()` display my plot? `plt.savefig('myplot.png')` works, however.
thanksGeremiaTue, 10 Mar 2015 00:44:23 +0100https://ask.sagemath.org/question/26122/How to clear the screen?https://ask.sagemath.org/question/25751/how-to-clear-the-screen/Hey!
I am using Sage in the Sage cloud website.
I have an infinite loop that shows a result each time it is run, only I don't want to see a billion results in my display, i'd like to clear the display everytime the loop runs. I tried the "clear" function but it does not exist. Do you know any function that would clear the screen? Or an alternate way of doing the same thing (something like a dynamic way of displaying data)
Thank you :)DiventoxFri, 06 Feb 2015 19:05:40 +0100https://ask.sagemath.org/question/25751/