Show entire matrix

I have some narrow but long matrix (dataframe-like), and I’d like it to be displayed entirely in IJulia (or in the REPL). display(m) cuts it in the middle and shows only ~25 rows. show and print show everything, but the rows are not aligned. Is there any way to nicely display the whole matrix in tabular format?

1 Like

display("text/plain", rand(40, 5)) works. I’m not sure why “text/csv” isn’t supported - its error message is also very uninformative.

2 Likes

It seems like display on MIME"text/plain" defaults to limit=>false at least on Julia 1.2, so the current answer no longer works.

If there’s a better shorthand, let me know. But since this comes up on web searches still, I’ll revive the thread to show how to print the whole array:

show(IOContext(stdout, :limit=>false), MIME"text/plain"(), rand(40, 5))

6 Likes

This is also pretty cool.

1 Like

It would be nice to have a macro with this included (@showfull or something).

I agree that easier access to something like this would be nice to have.

@bocc: Would you mind suggesting this in an issue / implementing this in a PR over on GitHub, JuliaLang/julia?

A bit formatting (how many digits?) would also be useful. I have since long used my own (clumsy) printmat() function (available at my github page), but you are probably better off with
pretty_table(data, tf = borderless, noheader = true)
from PrettyTables.jl

show(stdout, "text/plain", matrix) should work and is pretty short. (No need to set an IOContext or create a MIME argument.)

6 Likes

If you want to use PrettyTables.jl to have more “freedom” then default Julia printing system, as @Paul_Soderlind mentioned, add the option crop = :none to avoid cropping or crop = :horizontal to only crop horizontally.

Furthermore, you can select how many digits will be printed using a formatter:

julia> m = rand(5,3);

julia> pretty_table(m, tf = borderless, noheader = true, crop = :horizontal, formatters = ft_round(3))
  0.888   0.544   0.776
  0.886   0.364   0.562
  0.745   0.367   0.393
  0.341   0.748   0.282
  0.702    0.62   0.206

Or, you can use the formatter ft_printf to format your numbers anyway you like:

julia> pretty_table(m, tf = borderless, noheader = true, crop = :horizontal, formatters = ft_printf("%3.1e"))
  8.9e-01   5.4e-01   7.8e-01
  8.9e-01   3.6e-01   5.6e-01
  7.4e-01   3.7e-01   3.9e-01
  3.4e-01   7.5e-01   2.8e-01
  7.0e-01   6.2e-01   2.1e-01

If you want to always use the same configuration and do not want to type a lot, then the macros @ptconf and @pt can help you. The former add configurations to a stack. The latter call pretty_table with such configuration:

julia> @ptconf tf = borderless noheader = true crop = :horizontal formatters = ft_printf("%3.2f")

julia> @pt m
  0.89   0.54   0.78
  0.89   0.36   0.56
  0.74   0.37   0.39
  0.34   0.75   0.28
  0.70   0.62   0.21

julia> @pt rand(4,4)
  0.66   0.91   0.37   0.77
  0.16   0.40   0.37   0.99
  0.58   0.04   0.87   0.86
  0.65   0.13   0.48   0.93

julia> @pt rand(5,5)
  0.67   0.50   0.72   0.33   0.32
  0.59   0.19   0.68   0.57   0.85
  0.21   0.75   0.08   0.35   0.01
  0.46   0.03   0.32   0.56   0.72
  0.73   0.92   0.25   0.97   0.12
4 Likes