JuliaLang / IJulia.jl

Julia kernel for Jupyter
MIT License
2.79k stars 409 forks source link

Gadfly plots displaying error? #496

Open xiaohk opened 7 years ago

xiaohk commented 7 years ago

When I run the code cells to plot in Jupyter, all plots are displayed correctly in my .ipynb file. Then I got the following issues:

  1. If I reopen the .ipynb file, all plots become texts, instead of a HTML or SVG block. image image
  2. I have pushed the ipynb file into Github, and some plots can't be displayed. For example, I wrote the following function (using a loop) to draw multiple plots:

    # Iterate within different λ
    function multiple_λ(λ_candidates)
    for my_λ in λ_candidates
        cost1, g1! = cost_and_gradient(zeros(28, 1), my_λ)
    
        # Find the parameters
        res = optimize(cost1, g1!, repeat([0.5], inner = size(feature, 2)))
        mini_Θ = Optim.minimizer(res)
    
        # Plot the decision boundaries
        l2 = layer(z = (x1,x2) -> decision(x1, x2, mini_Θ), 
                   x = linspace(-1.0, 1.5, 1000),
                   y = linspace(-1.0, 1.5, 1000),
                   Geom.contour(levels = [0.0]),
                   Theme(line_width = 1pt))
    
        p5 = plot(l1, l2, coord, 
                  Scale.color_discrete_manual(colorant"deep sky blue",
                                              colorant"light pink"),
                  Guide.title("Regularization with λ = $(my_λ)"))
    
        display(p5)
    end
    end

    If I run multiple_λ([1, 1, 1, 10, 10]), there should be 5 plots and the first three are identical as the last two are identical. On Github, only two plots are displayed correctly.

image image

The ipynb file can be visited here: https://github.com/xiaohk1997/test/blob/master/exercise2.ipynb

I have cross-posted this issue in Gadfly.jl. I am wondering how to fix it?

My Julia version is 0.5, and here is my Pkg.status()

julia> Pkg.status()
11 required packages:
 - Cairo                         0.2.35
 - Colors                        0.6.9
 - Fontconfig                    0.1.1
 - Gadfly                        0.5.2
 - IJulia                        1.3.3
 - ImageMagick                   0.1.8
 - ImageView                     0.2.0
 - Images                        0.5.14
 - MAT                           0.3.1
 - Optim                         0.7.4
 - QuartzImageIO                 0.1.4
60 additional packages:
 - AxisAlgorithms                0.1.5
 - BinDeps                       0.4.5
 - Blosc                         0.1.7
 - BufferedStreams               0.2.0
 - Calculus                      0.1.15
 - ColorTypes                    0.2.12
 - ColorVectorSpace              0.1.12
 - Compat                        0.10.0
 - Compose                       0.4.4
 - Conda                         0.4.0
 - Contour                       0.2.0
 - DataArrays                    0.3.11
 - DataFrames                    0.8.5
 - DataStructures                0.5.1
 - Dates                         0.4.4
 - DiffBase                      0.0.2
 - Distances                     0.3.2
 - Distributions                 0.11.1
 - FileIO                        0.2.1
 - FixedPointNumbers             0.2.1
 - FixedSizeArrays               0.2.5
 - ForwardDiff                   0.3.3
 - GZip                          0.2.20
 - Graphics                      0.1.3
 - HDF5                          0.7.2
 - Hexagons                      0.0.4
 - Hiccup                        0.1.1
 - Homebrew                      0.4.2
 - IniFile                       0.2.5
 - Interpolations                0.3.6
 - Iterators                     0.2.0
 - JSON                          0.8.0
 - Juno                          0.2.5
 - KernelDensity                 0.3.0
 - Libz                          0.2.1
 - LineSearches                  0.1.3
 - Loess                         0.1.0
 - MacroTools                    0.3.4
 - Measures                      0.0.3
 - Media                         0.2.4
 - NaNMath                       0.2.2
 - Nettle                        0.2.4
 - PDMats                        0.5.2
 - PositiveFactorizations        0.0.3
 - Ratios                        0.0.4
 - Reexport                      0.0.3
 - Rmath                         0.1.6
 - SHA                           0.3.0
 - SIUnits                       0.1.0
 - Showoff                       0.0.7
 - SortingAlgorithms             0.1.0
 - StatsBase                     0.12.0
 - StatsFuns                     0.3.1
 - TexExtensions                 0.0.3
 - Tk                            0.4.0
 - URIParser                     0.1.6
 - Winston                       0.12.1
 - WoodburyMatrices              0.2.1
 - ZMQ                           0.4.0
 - Zlib                          0.1.12
xiaohk commented 7 years ago

Related issue https://github.com/jupyter/notebook/issues/1521

Then how about issue 1?