Skip to content

Conversation

@t-bltg
Copy link
Member

@t-bltg t-bltg commented May 16, 2022

@FedeClaudi, I only started playing with Term.jl, this is awesome:

using UnicodePlots, Term

panel(plot; kw...) = Panel(string(plot, color=true); fit=true, kw...)

print(
  panel(lineplot([cos, sin], -π/2, 2π); title="lineplot", style="yellow") *
  panel(contourplot(-3:.01:3, -7:.01:3, (x, y) -> exp(-(x / 2)^2 - ((y + 2) / 4)^2)); title="contourplot", style="red") * 
  panel(surfaceplot(-8:.5:8, -8:.5:8, (x, y) -> 15sinc((x^2 + y^2) / π)); title="surfaceplot", style="blue") / (
    panel(histogram(randn(1_000_000), nbins=100, vertical=true); title="histogram", style="green") * 
    panel(densityplot(randn(1_000), randn(1_000)); title="densityplot", style="cyan")
  )
)

term-up

I'll update the example when a new release is out, removing the need for string(plot) as explained in FedeClaudi/Term.jl#86.

Fix #256.

@FedeClaudi
Copy link

That's so cool, I'm glad you like it!

removing the need for string(plot) as explained in

So I was initially thinking of having a Panel construct method dedicated to Plot objects, but that would require adding UnicodePlots to the dependencies just for that. Given the new string(plot) method that's not required anymore, the users can do Panel(string(plot; color=true)) and use Term's functionality as is.

Is that what you did to generate the examples above?


P.s.: Once you've released this, would it be okay if I tweet about it? It's such a beautiful use case for Term.jl!

@johnnychen94
Copy link
Collaborator

Didn't expect it worked out so smoothly 🎉

#238 (comment)
For the long-term goal that might never be achieved, I'm expecting to work closely with Term.jl, and eventually build a terminal-based IDE for Julia.

@t-bltg
Copy link
Member Author

t-bltg commented May 16, 2022

Is that what you did to generate the examples above?

I've updated the comment in #258 (comment) to show the code used (landing in README.md)

But with Term@master, I don't have to use string(...) anymore, this is sufficient:

using UnicodePlots, Term

print(
  Panel(lineplot([cos, sin], -π/2, 2π); title="lineplot", style="yellow", fit=true) *
  Panel(contourplot(-3:.01:3, -7:.01:3, (x, y) -> exp(-(x / 2)^2 - ((y + 2) / 4)^2)); title="contourplot", style="red", fit=true) * 
  Panel(surfaceplot(-8:.5:8, -8:.5:8, (x, y) -> 15sinc((x^2 + y^2) / π)); title="surfaceplot", style="blue", fit=true) / (
    Panel(histogram(randn(1_000_000), nbins=100, vertical=true); title="histogram", style="green", fit=true) * 
    Panel(densityplot(randn(1_000), randn(1_000)); title="densityplot", style="cyan", fit=true)
  )
)

Once you've released this, would it be okay if I tweet about it?

Sure, go ahead !

Didn't expect it worked out so smoothly

🚀 🚀 🚀

@FedeClaudi
Copy link

awesome, thanks!

@t-bltg
Copy link
Member Author

t-bltg commented May 16, 2022

Once you've released this

Btw, this PR is only documentation, the string(...) fix was released yesterday in [email protected].

@t-bltg t-bltg merged commit 1e25ebb into JuliaPlots:master May 16, 2022
@t-bltg t-bltg deleted the term branch May 16, 2022 17:53
@FedeClaudi
Copy link

Not sure if you're on twitter: https://twitter.com/Federico_claudi/status/1526297003797487616?s=20&t=_6SvMX84Q6VHuBX_hbLphQ

I like the idea of mixing plots and text using Term, feels like you can write a whole paper (or PhD Thesis @johnnychen94 ) in the terminal now:
image

Btw this is the code for it, I've added a bit of padding etc to make the layout more uniform:

using UnicodePlots, Term

panel(plot; kw...) = Panel(string(plot, color=true); fit=true, kw...)

print(
  panel(
    lineplot([cos, sin], -π/2, 2π); title="lineplot", style="yellow"
    ) * panel(
      contourplot(-3:.01:3, -7:.01:3, (x, y) -> exp(-(x / 2)^2 - ((y + 2) / 4)^2)); title="contourplot", style="red", padding=(4, 8, 1, 0),
    ) * panel(
      surfaceplot(-8:.5:8, -8:.5:8, (x, y) -> 15sinc((x^2 + y^2) / π)); title="surfaceplot", style="blue", padding=(11, 8, 1, 0)
    ) / (
    panel(
      histogram(randn(1_000_000), nbins=100, vertical=true); title="histogram", style="green"
    ) * Panel(
        string(densityplot(randn(1_000), randn(1_000)); color=true); title="densityplot", style="cyan", fit=true, padding=(0, 0, 1, 0)
    ) * TextBox(
      """     
                          [bold red underline]PLOT TYPES[/bold red underline]

              [white]⚪[/white] [bold bright_blue]scatterplot[/bold bright_blue]  (Scatter Plot)
              [white]⚪[/white] [bold bright_blue]lineplot[/bold bright_blue]     (Line Plot)
              [white]⚪[/white] [bold bright_blue]stairs[/bold bright_blue]       (Staircase Plot)
              [white]⚪[/white] [bold bright_blue]barplot[/bold bright_blue]      (Bar Plot - horizontal)
              [white]⚪[/white] [bold bright_blue]histogram[/bold bright_blue]    (Histogram - horizontal / vertical)
              [white]⚪[/white] [bold bright_blue]boxplot[/bold bright_blue]      (Box Plot - horizontal)
              [white]⚪[/white] [bold bright_blue]spy[/bold bright_blue]          (Sparsity Pattern)
              [white]⚪[/white] [bold bright_blue]densityplot[/bold bright_blue]  (Density Plot)
              [white]⚪[/white] [bold bright_blue]contourplot[/bold bright_blue]  (Contour Plot)
              [white]⚪[/white] [bold bright_blue]polarplot[/bold bright_blue]    (Polar Plot)
              [white]⚪[/white] [bold bright_blue]heatmap[/bold bright_blue]      (Heatmap Plot)
              [white]⚪[/white] [bold bright_blue]surfaceplot[/bold bright_blue]  (Surface Plot - 3D)
              [white]⚪[/white] [bold bright_blue]isosurface[/bold bright_blue]   (Isosurface Plot - 3D)
      """, padding=(2, 2, 1, 0)
        )
  )
)

@t-bltg
Copy link
Member Author

t-bltg commented May 17, 2022

I like the idea of mixing plots and text using Term, feels like you can write a whole paper

We only lack LaTeX there ...

All the existing solutions require rendering latex code to an image (and additional sixel encoding for enhanced resolution):

https://discourse.julialang.org/t/latex-rendering-in-the-julia-repl/43473/9
JuliaImages/ImageInTerminal.jl#49
#153

How does Term.jl behave with these ? It'd be awesome to be able to work with LaTeXStrings and render them auto-magically between plots and regular text.

@FedeClaudi
Copy link

It would be awesome to have Latex in the terminal, but not sure how feasible it is. I think you do have to go through an image as you can't have an unicode symbol for everything (though see this python package).

I've never looked into how images are rendered in the terminal, I've got no idea how it works it seems like magic to me. I'm sure @johnnychen94 knows a lot more about it. I haven't tried playing around with that in Term.jl, but if they can be turned into strings it should just work out of the box. Perhaps we can start a discussion on term's repo on how to best integrate it with images libraries?

@johnnychen94
Copy link
Collaborator

johnnychen94 commented May 18, 2022

Let's move the discussion to FedeClaudi/Term.jl#93

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Subplots with Term.jl - proposal

3 participants