<commit_before>
# https://github.com/stevengj/PyPlot.jl


const _pyplot_attr = merge_with_base_supported([
    :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, :fill_z,
    :levels,
    :ribbon, :quiver, :arrow,
    :orientation,
    :overwrite_figure,
    :polar,
    :normalize, :weights,
    :contours, :aspect_ratio,
    :match_dimensions,
    :clims,
    :inset_subplots,
    :dpi,
    :colorbar_title,
  ])
const _pyplot_seriestype = [
        :path, :steppre, :steppost, :shape,
        :scatter, :hexbin, #:histogram2d, :histogram,
        # :bar,
        :heatmap, :pie, :image,
        :contour, :contour3d, :path3d, :scatter3d, :surface, :wireframe
    ]
const _pyplot_style = [:auto, :solid, :dash, :dot, :dashdot]
const _pyplot_marker = vcat(_allMarkers, :pixel)
const _pyplot_scale = [:identity, :ln, :log2, :log10]
is_marker_supported(::PyPlotBackend, shape::Shape) = true


# --------------------------------------------------------------------------------------

function add_backend_string(::PyPlotBackend)
    """
    if !Plots.is_installed("PyPlot")
        Pkg.add("PyPlot")
    end
    withenv("PYTHON" => "") do
        Pkg.build("PyPlot")
    end
    """
end

function _initialize_backend(::PyPlotBackend)
    @eval begin
        # problem: https://github.com/tbreloff/Plots.jl/issues/308
        # solution: hack from @stevengj: https://github.com/stevengj/PyPlot.jl/pull/223#issuecomment-229747768
        otherdisplays = splice!(Base.Multimedia.displays, 2:length(Base.Multimedia.displays))
        import PyPlot, PyCall
        import LaTeXStrings: latexstring
        append!(Base.Multimedia.displays, otherdisplays)

        export PyPlot
        const pycolors = PyPlot.pywrap(PyPlot.pyimport("matplotlib.colors"))
        const pypath = PyPlot.pywrap(PyPlot.pyimport("matplotlib.path"))
        const mplot3d = PyPlot.pywrap(PyPlot.pyimport("mpl_toolkits.mplot3d"))
        const pypatches = PyPlot.pywrap(PyPlot.pyimport("matplotlib.patches"))
        const pyfont = PyPlot.pywrap(PyPlot.pyimport("matplotlib.font_manager"))<commit_msg>working on fixing pyplot issue for ubuntu<commit_after>
# https://github.com/stevengj/PyPlot.jl


const _pyplot_attr = merge_with_base_supported([
    :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, :fill_z,
    :levels,
    :ribbon, :quiver, :arrow,
    :orientation,
    :overwrite_figure,
    :polar,
    :normalize, :weights,
    :contours, :aspect_ratio,
    :match_dimensions,
    :clims,
    :inset_subplots,
    :dpi,
    :colorbar_title,
  ])
const _pyplot_seriestype = [
        :path, :steppre, :steppost, :shape,
        :scatter, :hexbin, #:histogram2d, :histogram,
        # :bar,
        :heatmap, :pie, :image,
        :contour, :contour3d, :path3d, :scatter3d, :surface, :wireframe
    ]
const _pyplot_style = [:auto, :solid, :dash, :dot, :dashdot]
const _pyplot_marker = vcat(_allMarkers, :pixel)
const _pyplot_scale = [:identity, :ln, :log2, :log10]
is_marker_supported(::PyPlotBackend, shape::Shape) = true


# --------------------------------------------------------------------------------------

function add_backend_string(::PyPlotBackend)
    """
    if !Plots.is_installed("PyPlot")
        Pkg.add("PyPlot")
    end
    withenv("PYTHON" => "") do
        Pkg.build("PyPlot")
    end
    """
    if !Plots.is_installed("PyPlot")
        Pkg.add("PyPlot")
    end
    withenv("PYTHON" => "") do
        Pkg.build("PyPlot")
    end
    import Conda          # TODO since this only known to occur on Ubuntu we could also check the user's OS here
    Conda.add("qt=4.8.5") # run the old version of Conda
    # TO AVOID:
    # 1) Segfault when attempting to run pylplot
        # caused by Conda update to Segfault with qt >=4.8.6 on Ubuntu https://github.com/JuliaPy/PyPlot.jl/issues/234
    # 2) precomilation issue after updating Plots.jl
        #=
        INFO: Recompiling stale cache file /home/febbo/.julia/lib/v0.5/Plots.ji for module Plots.
        ERROR: LoadError: Declaring __precompile__(false) is not allowed in files that are being precompiled.
        in __precompile__(::Bool) at ./loading.jl:300
        in include_from_node1(::String) at ./loading.jl:488
        in macro expansion; at ./none:2 [inlined]
        in anonymous at ./<missing>:?
        in eval(::Module, ::Any) at ./boot.jl:234
        in process_options(::Base.JLOptions) at ./client.jl:239
        in _start() at ./client.jl:318
        while loading /home/febbo/.julia/v0.5/Plots/src/Plots.jl, in expression starting on line 1
        ERROR: LoadError: Failed to precompile Plots to /home/febbo/.julia/lib/v0.5/Plots.ji.
        in compilecache(::String) at ./loading.jl:593
        in require(::Symbol) at ./loading.jl:393
        in include_from_node1(::String) at ./loading.jl:488
        =#
end

function _initialize_backend(::PyPlotBackend)
    @eval begin
        # problem: https://github.com/tbreloff/Plots.jl/issues/308
        # solution: hack from @stevengj: https://github.com/stevengj/PyPlot.jl/pull/223#issuecomment-229747768
        otherdisplays = splice!(Base.Multimedia.displays, 2:length(Base.Multimedia.displays))
        import PyPlot, PyCall
        import LaTeXStrings: latexstring
        append!(Base.Multimedia.displays, otherdisplays)

        export PyPlot
        const pycolors = PyPlot.pywrap(PyPlot.pyimport("matplotlib.colors"))
        const pypath = PyPlot.pywrap(PyPlot.pyimport("matplotlib.path"))
        const mplot3d = PyPlot.pywrap(PyPlot.pyimport("mpl_toolkits.mplot3d"))
        const pypatches = PyPlot.pywrap(PyPlot.pyimport("matplotlib.patches"))
        const pyfont = PyPlot.pywrap(PyPlot.pyimport("matplotlib.font_manager"))
{'fraction_non_alphanumeric': 0.1500988421349901, 'fraction_numerical': 0.01341428974865857, 'mean_word_length': 3.2210965435041716, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 8, 'https://': 7, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1422690', 'n_tokens_mistral': 2578, 'n_tokens_neox': 2395, 'n_words': 468}