Loading [MathJax]/jax/output/HTML-CSS/jax.js
Ask Your Question
2

How to change width of output in sagemath notebook?

asked 4 years ago

Dominik Stępień gravatar image

updated 0 years ago

FrédéricC gravatar image

I am working with big matrices and when I want to print them rows of matrix don't fit in one line of output and it is broken up although there is space on the screen left. Such printing makes matrix unreadable is there anyway to change this?

Preview: (hide)

Comments

Can you provide a minimal example? For instance a matrix with one row and the least number of columns to illustrate the issue.

slelievre gravatar imageslelievre ( 4 years ago )

1 Answer

Sort by » oldest newest most voted
2

answered 4 years ago

mwageringel gravatar image

There are several options that may be useful when working with large matrices.

According to this answer, you can make the output cells as wide as your browser window like this:

from IPython.core.display import display, HTML
display(HTML("<style>.container { width:100% !important; }</style>"))

The way matrices render depends on Sage's display mode setting. You can use latex rendering which shows the matrix without wrapping, possibly with scroll bars:

%display None      # this is the default setting
show(matrix.random(RDF, 3, 6))

(0.53357292174188830.331898317169100570.87711487472251020.141677033580894780.034767295798118660.74266965944042450.52649882504269050.96132639780465360.51933186710274740.505022990851770.99654969123715740.24435273603247710.876306299776010.41450650088443130.110821269552364710.361415682082119270.57942581982533860.5378936808115167)

Alternatively, to use latex rendering for everything:

%display latex
matrix.random(RDF, 3, 6)

In the terminal, you can view the latex rendered output in an external PDF viewer:

view(matrix.random(RDF, 3, 6))

As of Sage 9.1, another option is to use ascii_art or unicode_art for the display.

sage: %display unicode_art
sage: matrix.random(RDF, 3, 6)
  0.7857496475272576  -0.5621432349663726  -0.6197864217688647
⎜-0.09602225319381907   0.6310818306433721  0.04663485890726049
   0.364267304071475   0.8731639828344335 -0.22804442057132857

   0.2696959663485283   0.4186525964528831  -0.8423186241521643
 -0.49765470886120133   0.4748930267502407   0.4784913888617619
   0.6678112962808911  -0.7422772589338069   0.5578165726172355

In the terminal, the above makes use of the full width of the terminal window. In the notebook, it defaults to 80 columns - you can set a higher column number like this:

sage: %display unicode_art 100
sage: matrix.random(RDF, 3, 6)
 0.41816693194292154  0.26120840306318804   -0.837348560208534 -0.45806384657796806
  0.7240198735200238  -0.3906634900294397  -0.4104572268754003    0.987926730666215
⎝-0.16185556154081815 -0.03065482370398409  -0.3616997572776217  -0.8037967794680001

    0.841751537119509  -0.9660050207134228
   0.8075498876793383  -0.7844231138398663
   0.8499554630711053  0.18744229144965852
Preview: (hide)
link

Your Answer

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

Add Answer

Question Tools

Stats

Asked: 4 years ago

Seen: 655 times

Last updated: Jun 08 '20