Showing posts with label plotlyjs. Show all posts
Showing posts with label plotlyjs. Show all posts

Sunday, March 11, 2018

NodeJS - install package - plotly.js

Installing a package using npm:


First, let us search for the existance of the package - plotly.js

:~$ npm search plotly.js 
NAME                      | DESCRIPTION          | AUTHOR          | DATE       | VERSION  | KEYWORDS                                   
plotly.js                 | The open source…     | =alexcjohnson…  | 2018-03-09 | 1.35.2   | graphing plotting data visualization plotly
:~$ 


Now, we install plotly.js using the following command:

~$ npm install plotly.js
npm WARN deprecated nomnom@1.8.1: Package no longer supported. Contact support@npmjs.com for more info.
npm WARN saveError ENOENT: no such file or directory, open '/home/ubuntu/package.json'
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN enoent ENOENT: no such file or directory, open '/home/ubuntu/package.json'
npm WARN ubuntu No description
npm WARN ubuntu No repository field.
npm WARN ubuntu No README data
npm WARN ubuntu No license field.

+ plotly.js@1.35.2
added 495 packages in 70.718s
~$

After, plotly.js is installed we can check for its documentation using the explore command:

~$ npm explore plotly.js
~$

Looks like local documentation is not available. Hence, let us check its online documentation using the following command:

~$ sudo npm docs plotly.js

This command opens the online documentation in your default browser.




Saturday, September 16, 2017

Julia - Language - PlotlyJS - The standard normal distribution

For the explanation of normal distribution, refer the following video from Khan Academy:







Function
Purpose
randn()
Returns an array of randomly selected values from the - Standard Normal Distribution. The majority of values cluster around the mean of 0 and a standard deviation of 1.


First, import the following packages:

$ julia
               _
   _       _ _(_)_     |  A fresh approach to technical computing
  (_)     | (_) (_)    |  Documentation: https://docs.julialang.org
   _ _   _| |_  __ _   |  Type "?help" for help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 0.6.0 (2017-06-19 13:05 UTC)
 _/ |\__'_|_|_|\__'_|  |  Official http://julialang.org/ release
|__/                   |  x86_64-pc-linux-gnu

julia> using Distributions

julia> using Plots

julia> plotlyjs()
Plots.PlotlyJSBackend()

julia> using StatPlots
INFO: Precompiling module TableTraits.
INFO: Precompiling module DataValues.
INFO: Precompiling module KernelDensity.
INFO: Precompiling module Loess.

julia> using HypothesisTests
INFO: Precompiling module HypothesisTests.

julia> using DataFrames

julia> using GLM
INFO: Precompiling module GLM.

julia>

Let us get 10000 such values and attach this array to the variable arr_norm1.

julia> arr_norm1 = randn(10000);

julia> arr_norm1
10000-element Array{Float64,1}:
 -0.330113
 -0.526716
 -0.159486
 -1.50848
  0.0444939
 -2.24241
 -0.413104
  1.15788
 -0.74063
  1.3488
  0.404499
 -0.148054
  2.38449
  0.0247912
 -0.846278
 -0.116104
  1.91943
  0.0293767
  0.649929
  ⋮      
 -0.231188
 -0.243903
  0.145286
 -1.68122
  1.39924
 -2.27001
  1.67537
 -0.595119
 -1.23359
  0.249857
 -0.332047
  0.485967
 -1.65663
  0.182978
 -0.220901
 -0.412765
  1.47191
 -0.547864

julia>


We can plot this as histogram. In the example below, we will use the keyword argument bins. Setting it to 20 means that between the minimum and maximum value we create 20 equally sized ranges and count how many values occur in each range.

julia> histogram(arr_norm1,bins=20,label="Standard Normal Distribution",title="Histogram 01")






These values were selected at random. We can check how close we came to to a real mean of 0 and a standard deviation of 1.


# finding mean
julia> mean(arr_norm1)
0.014639565332684248

#standard deviation using std()
julia> std(arr_norm1)
0.9959800381020006

# variance using var()
julia> var(arr_norm1)
0.9919762362976626

julia>