Julia: Plotting in the terminal, unicodeplots.jl ver. 8

Last Updated on September 5, 2022 by shibatau

Sorry but there may be some mistakes. I’m rewriting now.

I. Installing Julia on Mac

It is easy to install Julia using Brew for Mac. Run the following code in the terminal.

brew install --cask julia

You can learn more here:

https://formulae.brew.sh/cask/julia

II. Installing Julia on Kali Linux

You can learn how to install Julia on Kali Linux here:

Installing Kali Linux on MacBook Air

III. Creating your project

The codes look complicated but they will look a lot simpler when you learn these commands and codes:

Start Shell REPL from Julia REPL

julia> ;

Start Julia REPL from Shell REPL

Press Backspace

Start Pkg REPL from Julia REPL

]

Go back to Julia REPL from Pkg Repl

Press Backspace

In the Shell REPL

Move to Home Directory

shell> cd

Move to Desktop Directory from Home Directory

shell> Desktop

Creating your project

# run the command in the terminal to open Julia
julia
# start Shell REPL
;
# move to Home directory
shell> cd
# move to Desktop
shell> cd Desktop
# start Julia REPL
Press Backspace
# start Pkg REPL
julia> ]
# create the source tree and toml files
pkg > generate MyProject

Now you have created a directory that contains Project.toml and another directory that contains MyProject.jl.

## activate the project
# start Julia REPL
Press Backspace
# start Shell REPL
julia> ;
# move to MyProject
shell> cd MyProject
# start Julia REPL
Press Backspace
# start Pkg REPL
julia> ]
# activate the project
pkg> activate .

Now I will show you how to activate the project. Let’s open Julia, change directories, and call the greet function that was automatically created when you created the source tree and TOML files.

You can learn more here:

https://www.matecdev.com/posts/julia-create-project.html

https://pkgdocs.julialang.org/v1/environments/

IV. Plotting in the terminal in Neovim on Kali Linux

Run the command in the terminal:

nvim

Run the command on Neovim for nvim-tree

:NvimTreeToggle

Type these keys to move to the right window:

Ctrl + w + w

Run the command on Neovim for splitting the window horizontally:

:split

Run the command on Neovim for opening julia in the terminal:

:term julia

type i to enter the insert mode and run the codes.

You can also activate a virtual environment with the code:

pkg> activate YOURENVIRONMENT

Let’s create a simple line chart for the results of English examination in one of my sample datasets.

# install packages
pkg> add uCSV
pkg> add DataFrames
pkg> add HTTP
pkg> add UnicodePlots
# show list of the packages installed
using Pkg
Pkg.update()
Pkg.status()
# use libraries
using uCSV, DataFrames, HTTP, UnicodePlots
# load the data
html = "https://pastebin.com/raw/cSZ8pYWh"
df = DataFrame(uCSV.read(IOBuffer(HTTP.get(html).body), quotes='"', header=1))
# show the first 5 rows
first(df, 5)
# summarize the data
describe(df)
# group the data by nationality
df_nationality = groupby(df, :nationality)
# calculate the means of english scores by nationality using Statistics
using Statistics
english_nationality_mean = combine(df_nationality, :english => mean)
# create a bar plot
barplot(english_nationality_mean[:, 1],
        english_nationality_mean[:,2],
        title="English scores by nationality") 

Let me paste the codes as texts here. Please compare them to the image above.

julia> # create a bar plot
       barplot(english_nationality_mean[:, 1],
               english_nationality_mean[:,2],
               title="English scores by nationality") 
                    English scores by nationality       
             ┌                                        ┐ 
       japan ┤■■■■■■■■■■■ 37.133333333333304            
       nepal ┤■■■■■■■■■■■■■■■■■■■■■ 69.31153846153848   
   indonesia ┤■■■■■■■■■■■■■■■ 51.1                      
       china ┤■■■■■■■■■■■■■ 43.15                       
     vietnam ┤■■■■■■■■■■■■■■ 45.833333333333336         
             └                                        ┘ 

You can learn more here:

https://github.com/JuliaPlots/UnicodePlots.jl#barplot

Plotting in the Terminal — An Unconventional Approach to Data Visualization

About shibatau

I was born and grown up in Kyoto. I studied western philosophy at the University and specialized in analytic philosophy, especially Ludwig Wittgenstein at the postgraduate school. I'm interested in new technology, especially machine learning and have been learning R language for two years and began to learn Python last summer. Listening toParamore, Sia, Amazarashi and MIyuki Nakajima. Favorite movies I've recently seen: "FREEHELD". Favorite actors and actresses: Anthony Hopkins, Denzel Washington, Ellen Page, Meryl Streep, Mia Wasikowska and Robert DeNiro. Favorite books: Fyodor Mikhailovich Dostoyevsky, "The Karamazov Brothers", Shinran, "Lamentations of Divergences". Favorite phrase: Salvation by Faith. Twitter: @shibatau

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.