JuliaOpt / MathProgBase.jl

DEPRECATED: Solver-independent functions (i.e. linprog and mixintprog) and low-level interface for Mathematical Programming
Other
80 stars 38 forks source link

load error #206

Closed nassim15 closed 6 years ago

nassim15 commented 6 years ago

please, who can help me i got this issue using julia 0.5

UndefVarError: cf not defined

in include_string(::String, ::String) at ./loading.jl:441 in include_string(::String, ::String) at /Applications/Julia-0.5.app/Contents/Resources/julia/lib/julia/sys.dylib:?

blegat commented 6 years ago

Where you do get this issue from ? What is the script that you execute that give you this error ? There is not cf in this package.

nassim15 commented 6 years ago

there is the script

using HDF5, PyCall, PyPlot
vsc15 = h5read("Results_015_001_001.h5","/vscZ");
v15 = vsc15;
bz15 = h5read("Results_015_001_001.h5","/bZ");
b15 = bz15;
df15 = h5read("Results_015_001_001.h5","/dfZ");
d15 = df15;
vsc30 = h5read("Results_030_001_001.h5","/vscZ");
v30 = vsc30;
bz30 = h5read("Results_030_001_001.h5","/bZ");
b30 = bz30;
df30 = h5read("Results_030_001_001.h5","/dfZ");
d30 = df30;
vsc50 = h5read("Results_050_001_001.h5","/vscZ");
v50 = vsc50;
bz50 = h5read("Results_050_001_001.h5","/bZ");
b50 = bz50;
df50 = h5read("Results_050_001_001.h5","/dfZ");
d50 = df50;
plt = PyPlot;
global cmin = -9e10;
global cmax = 9e10;
contourlevels = collect(cmin:(cmax-cmin)/5:cmax);
cmaplevels = length(contourlevels)-1;
colors = plt.cm[:viridis](linspace(0,1,cmaplevels));
New_magma=plt.LinearSegmentedColormap[:from_list]("New_magma",colors,N=cmaplevels);
function subfig(plotnum::Int64, ax::PyCall.PyObject)
    if(plotnum==1)
        cf = ax[:imshow](v15', origin="lower", vmin=cmin, vmax=cmax, cmap=New_magma)
        return cf
    elseif(plotnum==2)
        cf = ax[:imshow](v30', origin="lower", vmin=cmin, vmax=cmax, cmap=New_magma)
        return cf
    elseif(plotnum==3)
        cf = ax[:imshow](v50', origin="lower", vmin=cmin, vmax=cmax, cmap=New_magma)
        return cf
    elseif(plotnum==4)
        cf = ax[:imshow](b15', origin="lower", vmin=cmin, vmax=cmax, cmap=New_magma)
        return cf
    elseif(plotnum==5)
        cf = ax[:imshow](b30', origin="lower", vmin=cmin, vmax=cmax, cmap=New_magma)
        return cf
    elseif(plotnum==6)
        cf = ax[:imshow](b50', origin="lower", vmin=cmin, vmax=cmax, cmap=New_magma)
        return cf
    elseif(plotnum==7)
        cf = ax[:imshow](d15', origin="lower", vmin=cmin, vmax=cmax, cmap=New_magma)
        return cf
    elseif(plotnum==8)
        cf = ax[:imshow](d30', origin="lower", vmin=cmin, vmax=cmax, cmap=New_magma)
        return cf
    elseif(plotnum==9)
        cf = ax[:imshow](d50', origin="lower", vmin=cmin, vmax=cmax, cmap=New_magma)
        return cf

    end
end
num_rows, num_cols = 3, 3
fig, axes = plt.subplots(num_rows, num_cols, sharey="row", sharex=true, squeeze=true)
subplot_num = 0

for i in 1:num_rows
    for j in 1:num_cols
        subplot_num += 1;
        ax = axes[i, j];
        ax[:tick_params](axis="both", which="both", direction="in", left="on", bottom="on", top="on", right="on")
        cf = subfig(subplot_num, ax)
        #ax[:set_xticks]([0,25,50])
        #ax[:set_yticks]([0,25,50])
        ax[:set_xlim](0,1820)
        ax[:set_ylim](0,1634)
        ax[:set_xlabel](L"x")
        ax[:set_ylabel](L"y")
        #ax[:autoscale](enable=true, axis="X", tight=true)
        ax[:grid]("off")
    end
end

cax = fig[:add_axes]([1, 0.1, 0.03, 0.8])
fig[:colorbar](cf, cax=cax)
#fig[:colorbar](cf, cax=cax, ticks=contourlevels[1:1:end])
#plt.savefig("adv_dif_prod.pdf")

@pyimport matplotlib2tikz
matplotlib2tikz.save("vsc_vsg_bar_dfv.tex", figureheight = "\\figureheight", figurewidth = "\\figurewidth", dpi=300)
blegat commented 6 years ago

The variable cf is defined inside the for loop so it is not accessible outside. For instance

julia> for i in 1:2
           j = i
       end

julia> j
ERROR: UndefVarError: j not defined
Stacktrace:
 [1] macro expansion at ./REPL.jl:97 [inlined]
 [2] (::Base.REPL.##1#2{Base.REPL.REPLBackend})() at ./event.jl:73

This has nothing to do with this package though. For such question, the best place to ask is discourse