In [1]:
# Declaramos la variable de entorno "PYTHON" vacia.
ENV["PYTHON"]=""

Pkg.update()


INFO: Updating METADATA...
INFO: Updating Interact...
INFO: Updating Plots...
INFO: Computing changes...
INFO: No packages to install, update or remove

In [4]:
ENV["PYTHON"] = ""
using Plots, StatPlots, PlotRecipes

Plots with Plots.jl, Tom Breloff


In [3]:
plot(Plots.fakedata(50,5),w=3)


[Plots.jl] Initializing backend: pyplot
INFO: Recompiling stale cache file /Users/roman/.julia/lib/v0.4/PyPlot.ji for module PyPlot.
INFO: Recompiling stale cache file /Users/roman/.julia/lib/v0.4/PyCall.ji for module PyCall.
INFO: Recompiling stale cache file /Users/roman/.julia/lib/v0.4/Conda.ji for module Conda.
INFO: Recompiling stale cache file /Users/roman/.julia/lib/v0.4/MacroTools.ji for module MacroTools.
INFO: Recompiling stale cache file /Users/roman/.julia/lib/v0.4/LaTeXStrings.ji for module LaTeXStrings.
Out[3]:
sys:1: MatplotlibDeprecationWarning: The set_axis_bgcolor function was deprecated in version 2.0. Use set_facecolor instead.

Por qué Julia

  • Es fácil de programar
  • el "multiple dispatch" es poderoso e intuitivo
  • Se pueden usar "macros"
  • El código simplemente se ve limpio

Aquí los macros son programas creados de antemano y utilizados de manera fácil. Por ejemplo: @layout. Así que el layout puede entrar directamente (como veremos, o através de un macro). Por ejemplo, dentro de plot:


In [6]:
plot(randn(100,5),layout= 5,
t=[:line :histogram :scatter :steppre :bar],leg=false,ticks=nothing,border=false)


[Plots.jl] Initializing backend: pyplot
Out[6]:
sys:1: MatplotlibDeprecationWarning: The set_axis_bgcolor function was deprecated in version 2.0. Use set_facecolor instead.

In [7]:
l = @layout [a{0.1h};b [c;d e]]
plot(randn(100,5),layout= l,
t=[:line :histogram :scatter :steppre :bar],leg=false,ticks=nothing,border=false)


Out[7]:

Insertar una imagen

Figure 1


In [9]:
plotattr(:Series)


UndefVarError: plotattr not defined

In [14]:
plot(rand(100), line = (:steppre, :dot, :arrow, 0.5, 4, :red))


Out[14]:

In [15]:
plot(rand(100), fill = (0, 0.5, :red))


Out[15]:

In [16]:
scatter(rand(100), marker = (:hexagon, 20, 0.6, :green, stroke(3, 0.2, :black, :dot)))


WARNING: Keyword argument markerstrokestyle not supported with Plots.PyPlotBackend().  Choose from: [:annotations,:background_color_legend,:background_color_inside,:background_color_outside,:foreground_color_grid,:foreground_color_legend,:foreground_color_title,:foreground_color_axis,:foreground_color_border,:foreground_color_guide,:foreground_color_text,:label,:linecolor,:linestyle,:linewidth,:linealpha,:markershape,:markercolor,:markersize,:markeralpha,:markerstrokewidth,:markerstrokecolor,:markerstrokealpha,:fillrange,:fillcolor,:fillalpha,:bins,:bar_width,:bar_edges,:bar_position,:title,:title_location,:titlefont,:window_title,:guide,:lims,:ticks,:scale,:flip,:rotation,:tickfont,:guidefont,:legendfont,:grid,:legend,:colorbar,:marker_z,:line_z,:levels,:ribbon,:quiver,:arrow,:orientation,:overwrite_figure,:polar,:normalize,:weights,:contours,:aspect_ratio,:match_dimensions,:clims,:inset_subplots,:dpi,:color_palette,:background_color,:background_color_subplot,:foreground_color,:foreground_color_subplot,:group,:seriestype,:seriescolor,:seriesalpha,:smooth,:xerror,:yerror,:subplot,:x,:y,:z,:show,:size,:margin,:left_margin,:right_margin,:top_margin,:bottom_margin,:html_output_format,:layout,:link,:primary,:series_annotations,:subplot_index,:discrete_values,:projection,:xforeground_color_axis,:yforeground_color_axis,:zforeground_color_axis,:xforeground_color_border,:yforeground_color_border,:zforeground_color_border,:xforeground_color_guide,:yforeground_color_guide,:zforeground_color_guide,:xforeground_color_text,:yforeground_color_text,:zforeground_color_text,:xguide,:yguide,:zguide,:xlims,:ylims,:zlims,:xticks,:yticks,:zticks,:xscale,:yscale,:zscale,:xflip,:yflip,:zflip,:xrotation,:yrotation,:zrotation,:xtickfont,:ytickfont,:ztickfont,:xguidefont,:yguidefont,:zguidefont,:xlink,:ylink,:zlink,:xdiscrete_values,:ydiscrete_values,:zdiscrete_values]
Out[16]:

Con datos reales de viento solar

3 componenbtes del campo magnético interplanetario, concentración, temperatura, velocidad del viento solar y, como referencia, el índice geomagnético Dst


In [12]:
vs = readdlm("omni2_14800.lst")


Out[12]:
720x11 Array{Float64,2}:
 2012.0  153.0   0.0   5.1  -3.7   2.9  -1.7   13718.0   8.4  358.0   27.0
 2012.0  153.0   1.0   5.0  -3.9   1.7  -2.5   12482.0   8.4  355.0   23.0
 2012.0  153.0   2.0   5.2  -4.5   0.9  -2.5   10074.0   7.0  354.0   19.0
 2012.0  153.0   3.0   4.8  -2.8  -2.3  -1.5   15801.0   7.9  364.0   18.0
 2012.0  153.0   4.0   5.3   1.0  -5.0   1.4   12985.0   5.6  366.0   17.0
 2012.0  153.0   5.0   5.7   1.9  -4.8   2.5    9368.0   3.8  361.0   15.0
 2012.0  153.0   6.0   5.8   2.3  -3.9   3.5    9684.0   4.2  357.0   18.0
 2012.0  153.0   7.0   6.0   2.0  -3.9   4.0    9549.0   3.4  358.0   19.0
 2012.0  153.0   8.0   6.1   2.1  -3.0   4.8   11203.0   3.0  353.0   19.0
 2012.0  153.0   9.0   6.2   2.0  -3.1   5.0   11891.0   2.8  350.0   19.0
 2012.0  153.0  10.0   6.2   1.6  -1.6   5.7   14798.0   3.3  354.0   24.0
 2012.0  153.0  11.0   5.8   1.3  -1.0   5.5   21869.0   5.3  363.0   29.0
 2012.0  153.0  12.0   5.0   1.5  -2.4   2.7   28406.0   7.8  363.0   24.0
    ⋮                              ⋮                                   ⋮  
 2012.0  182.0  12.0  11.4   4.7  -5.5  -3.8  492838.0  11.1  606.0    3.0
 2012.0  182.0  13.0  11.1   5.6  -3.7   3.0  448548.0  12.2  601.0    6.0
 2012.0  182.0  14.0  11.1   5.6   0.8  -1.5  400412.0  10.5  615.0    1.0
 2012.0  182.0  15.0   9.7   7.5   0.2   0.1  414347.0  10.1  612.0    1.0
 2012.0  182.0  16.0   9.7   3.1   2.5   3.1  393268.0   8.3  630.0    0.0
 2012.0  182.0  17.0   6.6   5.6   1.1   0.1  194462.0   4.1  653.0  -10.0
 2012.0  182.0  18.0   6.5   4.5   1.7  -1.7  222312.0   3.9  659.0   -7.0
 2012.0  182.0  19.0   6.8   2.1  -1.5  -2.0  251894.0   4.0  675.0  -15.0
 2012.0  182.0  20.0   7.2   1.1  -6.7   0.1  259096.0   3.7  675.0  -19.0
 2012.0  182.0  21.0   7.0   2.4  -3.5  -2.6  284265.0   3.9  656.0  -15.0
 2012.0  182.0  22.0   6.4   4.5  -1.1  -0.6  321643.0   4.6  633.0  -12.0
 2012.0  182.0  23.0   7.6   4.3  -4.2  -0.3  265153.0   4.1  639.0  -13.0

In [13]:
matricita = [vs[:,5:7] vs[:,10] vs[:,11]]


Out[13]:
720x5 Array{Float64,2}:
 -3.7   2.9  -1.7  358.0   27.0
 -3.9   1.7  -2.5  355.0   23.0
 -4.5   0.9  -2.5  354.0   19.0
 -2.8  -2.3  -1.5  364.0   18.0
  1.0  -5.0   1.4  366.0   17.0
  1.9  -4.8   2.5  361.0   15.0
  2.3  -3.9   3.5  357.0   18.0
  2.0  -3.9   4.0  358.0   19.0
  2.1  -3.0   4.8  353.0   19.0
  2.0  -3.1   5.0  350.0   19.0
  1.6  -1.6   5.7  354.0   24.0
  1.3  -1.0   5.5  363.0   29.0
  1.5  -2.4   2.7  363.0   24.0
  ⋮                            
  4.7  -5.5  -3.8  606.0    3.0
  5.6  -3.7   3.0  601.0    6.0
  5.6   0.8  -1.5  615.0    1.0
  7.5   0.2   0.1  612.0    1.0
  3.1   2.5   3.1  630.0    0.0
  5.6   1.1   0.1  653.0  -10.0
  4.5   1.7  -1.7  659.0   -7.0
  2.1  -1.5  -2.0  675.0  -15.0
  1.1  -6.7   0.1  675.0  -19.0
  2.4  -3.5  -2.6  656.0  -15.0
  4.5  -1.1  -0.6  633.0  -12.0
  4.3  -4.2  -0.3  639.0  -13.0

In [18]:
etiqs = ["Bx" "By" "Bz" "Vel" "Dst"]
equis = ["" "" "" "" "June 2012"]
plot(matricita, layout = (5,1), fill=(0,0.3,:blue), ylabel = etiqs, 
xlabel = equis, xticks = nothing)


Out[18]:

Evento de referencia

Tormenta geomagnética del 20 de noviembre de 2003


In [19]:
vsref = readdlm("omni2_486.txt")


Out[19]:
603x11 Array{Float64,2}:
 2003.0  305.0   0.0  6.3  -3.4  -1.2  -0.6   17520.0  1.7  804.0  -69.0
 2003.0  305.0   1.0  4.0  -1.4  -1.8  -1.5   14982.0  1.5  801.0  -69.0
 2003.0  305.0   2.0  3.2  -1.4  -3.6  -3.2   12216.0  1.9  789.0  -61.0
 2003.0  305.0   3.0  4.3  -1.2  -2.3  -1.9   16531.0  1.6  770.0  -62.0
 2003.0  305.0   7.0  4.7  -1.5  -1.4  -0.6   10813.0  1.4  710.0  -48.0
 2003.0  305.0   8.0  4.7  -0.3  -1.7  -1.4    9101.0  1.5  699.0  -47.0
 2003.0  305.0  17.0  4.6  -1.5  -0.6  -0.2   12344.0  2.4  615.0  -31.0
 2003.0  305.0  18.0  1.8  -3.3  -2.7  -1.9   12960.0  2.2  638.0  -28.0
 2003.0  305.0  19.0  3.2  -2.3  -2.9  -2.4   11654.0  2.4  610.0  -32.0
 2003.0  305.0  20.0  3.2  -2.2  -3.1  -2.7   13096.0  2.6  610.0  -36.0
 2003.0  305.0  21.0  3.8  -3.0  -1.3  -0.8   13955.0  2.3  596.0  -33.0
 2003.0  305.0  22.0  3.0  -2.7  -2.6  -2.2   14915.0  2.2  595.0  -31.0
 2003.0  305.0  23.0  3.2  -2.3  -2.7  -2.3   19284.0  2.5  591.0  -37.0
    ⋮                             ⋮                                  ⋮  
 2003.0  334.0  12.0  8.0   1.4   5.1   4.4  148622.0  8.6  467.0   14.0
 2003.0  334.0  13.0  9.3   0.5  -0.7  -0.8  146904.0  7.0  477.0    7.0
 2003.0  334.0  14.0  9.7  -4.6  -5.8  -4.4  129393.0  5.0  488.0   -3.0
 2003.0  334.0  15.0  7.8  -5.7  -6.0  -4.7  121637.0  5.0  488.0   -3.0
 2003.0  334.0  16.0  9.3  -0.4  -2.2  -2.1  165978.0  5.8  474.0   -9.0
 2003.0  334.0  17.0  6.1  -3.9  -5.0  -4.5   99855.0  4.9  484.0  -23.0
 2003.0  334.0  18.0  4.9  -4.3  -5.4  -5.1   85873.0  4.4  485.0  -30.0
 2003.0  334.0  19.0  4.6  -3.5  -5.6  -5.5  100907.0  3.8  489.0  -34.0
 2003.0  334.0  20.0  5.2  -2.6  -3.3  -3.3  102006.0  3.7  479.0  -39.0
 2003.0  334.0  21.0  5.4  -4.2  -3.7  -3.8   86345.0  3.3  475.0  -38.0
 2003.0  334.0  22.0  5.8  -3.4  -3.0  -3.1  106987.0  3.6  477.0  -33.0
 2003.0  334.0  23.0  3.9  -4.9  -3.1  -3.3  107009.0  3.2  482.0  -27.0

In [20]:
matref = [vsref[:,5:7] vsref[:,10] vsref[:,11] ]


Out[20]:
603x5 Array{Float64,2}:
 -3.4  -1.2  -0.6  804.0  -69.0
 -1.4  -1.8  -1.5  801.0  -69.0
 -1.4  -3.6  -3.2  789.0  -61.0
 -1.2  -2.3  -1.9  770.0  -62.0
 -1.5  -1.4  -0.6  710.0  -48.0
 -0.3  -1.7  -1.4  699.0  -47.0
 -1.5  -0.6  -0.2  615.0  -31.0
 -3.3  -2.7  -1.9  638.0  -28.0
 -2.3  -2.9  -2.4  610.0  -32.0
 -2.2  -3.1  -2.7  610.0  -36.0
 -3.0  -1.3  -0.8  596.0  -33.0
 -2.7  -2.6  -2.2  595.0  -31.0
 -2.3  -2.7  -2.3  591.0  -37.0
  ⋮                            
  1.4   5.1   4.4  467.0   14.0
  0.5  -0.7  -0.8  477.0    7.0
 -4.6  -5.8  -4.4  488.0   -3.0
 -5.7  -6.0  -4.7  488.0   -3.0
 -0.4  -2.2  -2.1  474.0   -9.0
 -3.9  -5.0  -4.5  484.0  -23.0
 -4.3  -5.4  -5.1  485.0  -30.0
 -3.5  -5.6  -5.5  489.0  -34.0
 -2.6  -3.3  -3.3  479.0  -39.0
 -4.2  -3.7  -3.8  475.0  -38.0
 -3.4  -3.0  -3.1  477.0  -33.0
 -4.9  -3.1  -3.3  482.0  -27.0

In [21]:
etiqsr = ["Bx" "By" "Bz" "Vel" "Dst"]
equisr = ["" "" "" "" "November 2003"]
plot(matref, layout = (5,1), fill=(0,0.3,:blue), ylabel = etiqsr, 
xlabel = equisr, xticks = nothing)


Out[21]:

Para comparar estos dos eventos, vamos a tomar 11 días de datos. Para el primero, que fue en día 16, tomaremos del 11 al 21, y para el segundo, que fue en día 20, tomaremos del 15 al 25.


In [22]:
tiempo1 = vs[:,1]+(vs[:,2]/365)+(vs[:,3]/(24*365))
tiempo2 = vsref[:,1]+vsref[:,2]/365+vsref[:,3]/(24*365)


Out[22]:
603-element Array{Float64,1}:
 2003.84
 2003.84
 2003.84
 2003.84
 2003.84
 2003.84
 2003.84
 2003.84
 2003.84
 2003.84
 2003.84
 2003.84
 2003.84
    ⋮   
 2003.92
 2003.92
 2003.92
 2003.92
 2003.92
 2003.92
 2003.92
 2003.92
 2003.92
 2003.92
 2003.92
 2003.92

In [23]:
s1 = plot(tiempo1, vs[:,10])
s2 = plot(tiempo2, vsref[:,10])
plot(s1, s2, layout = (2,1))


Out[23]:

In [24]:
plot(matricita[241:504,:], layout = (5,1), fill=(0,0.3,:blue), ylabel = etiqs, 
xlabel = equis, xticks = nothing)
plot!(matref[225:509,:], layout = (5,1), fill=(0,0.3,:red), ylabel = etiqsr, 
xlabel = equisr, xticks = nothing)


Out[24]:

Veamos otros layouts

Para lo que usaré sólo el campo magnético interplanetario


In [46]:
#imf = [vs[:,5:7]]
#imf = [vs[:,5:7] vs[:,5:7]] #como los voy a usar 2 veces, así los pongo en la matriz
imf = [vs[:,5] vs[:,5] vs[:,6] vs[:,6] vs[:,7] vs[:,7]] # otra opción


Out[46]:
720x6 Array{Float64,2}:
 -3.7  -3.7   2.9   2.9  -1.7  -1.7
 -3.9  -3.9   1.7   1.7  -2.5  -2.5
 -4.5  -4.5   0.9   0.9  -2.5  -2.5
 -2.8  -2.8  -2.3  -2.3  -1.5  -1.5
  1.0   1.0  -5.0  -5.0   1.4   1.4
  1.9   1.9  -4.8  -4.8   2.5   2.5
  2.3   2.3  -3.9  -3.9   3.5   3.5
  2.0   2.0  -3.9  -3.9   4.0   4.0
  2.1   2.1  -3.0  -3.0   4.8   4.8
  2.0   2.0  -3.1  -3.1   5.0   5.0
  1.6   1.6  -1.6  -1.6   5.7   5.7
  1.3   1.3  -1.0  -1.0   5.5   5.5
  1.5   1.5  -2.4  -2.4   2.7   2.7
  ⋮                             ⋮  
  4.7   4.7  -5.5  -5.5  -3.8  -3.8
  5.6   5.6  -3.7  -3.7   3.0   3.0
  5.6   5.6   0.8   0.8  -1.5  -1.5
  7.5   7.5   0.2   0.2   0.1   0.1
  3.1   3.1   2.5   2.5   3.1   3.1
  5.6   5.6   1.1   1.1   0.1   0.1
  4.5   4.5   1.7   1.7  -1.7  -1.7
  2.1   2.1  -1.5  -1.5  -2.0  -2.0
  1.1   1.1  -6.7  -6.7   0.1   0.1
  2.4   2.4  -3.5  -3.5  -2.6  -2.6
  4.5   4.5  -1.1  -1.1  -0.6  -0.6
  4.3   4.3  -4.2  -4.2  -0.3  -0.3

In [48]:
la0 = @layout [[a b];[c d];[d e]]
la = @layout [[a; b; c] [d e; f g]]
la1 = @layout [[a{0.7w} b]; [c d]; [e f]]
plot(imf, layout = la1, t = [:line :histogram], 
    fill=(0,0.3,:green))


Out[48]:

In [49]:
markers = setdiff(supported_markers(),[:none,:auto,Shape])'
n = length(markers)
x = (linspace(0,10,n + 2))[2:end - 1]
y = repmat(reverse(x)',n,1)
scatter(x,y,m=(8,:auto),lab=map(string,markers),bg=:linen,xlim=(0,10),ylim=(0,10))


Out[49]:

In [50]:
styles = setdiff(supported_styles(),[:auto])'
plot(cumsum(randn(20,length(styles)),1),style=:auto,label=map(string,styles),w=5)


Out[50]:

In [51]:
linetypes = [:path :steppre :steppost :sticks :scatter]
n = length(linetypes)
x = Vector[sort(rand(20)) for i = 1:n]
y = rand(20,n)
plot(x,y,line=(linetypes,3),lab=map(string,linetypes),ms=15)


Out[51]:

In [ ]: