Thank you for your replying. Although it is not what I wanted, I learned something new. Now about my “Warning” problem, for some reason it disappeared when I used pyplot ().
I am sorry I did not put my problem in more detail, but I will try to make amends by explaining what I wanted.
I was preparing a nonlinear programming class, and I needed to draw the feasible region of an example, using contour lines (it should be noted that I am a newbie to Julia). My problem was that when I compiled it I got a “Warning” message that I didn’t like, because it would look ugly when I presented it in class.
My initial code was:
using SymPy
using Plots @vars x y
g(x,y)=x+0.2y-3
h(x,y)=5-x-y
xs = range(-5,stop=7,length=50)
ys = range(-2,stop=12,length=50)
contour(xs,ys,h, levels=[0,2,3,20,30])
contour!(xs,ys,g, levels=[-7,-6,-5,-4,-3,-2,-1,-0.5,0])
and that was returning a “Warning” as you can see above.
And my last code, which didn’t return any “Warning” was
using SymPy
using Plots
pyplot() #added @vars x y
g(x,y)=x+0.2y-3
h(x,y)=5-x-y
xs = range(-5,stop=7,length=50)
ys = range(-2,stop=12,length=50)
contour(xs,ys,h, levels=[0,2,3,20,30])
contour!(xs,ys,g, levels=[-7,-6,-5,-4,-3,-2,-1,-0.5,0])
I think what is not understood is what was the expected result of the plotting.
What the warning is telling (as far as I understand) is: Your first plot draws contours with a defined colormap,a. In this plot, the last color of the colorbar will correspond to the value 30, and the first color in the colorbar will correspond to 0. In the second plot, which uses the same color scheme, the first color of the colorbar will correspond to -7 and the last color will correspond to 0.
So in the end, the colors of the first plot would not correspond to the same values as the same colors in the second call to contour.
Now, what is that you wanted?
Did you want a the colorbar to go from -7 to 30, and that both calls to contour used that scale (this is @rafael.guerra’s solution)? Or did you want to use two different colorbars to represent each of the calls?
So the warning is indeed useful, and the best way of avoiding it would depend on the sought result.
Sorry for taking time to reply, I was very busy.
What he wanted was the following.
I wanted a tool to draw feasible regions. For example if we have two functions f (x, y) and g (x, y), then how to graph the intersection of the regions f (x, y) <10 and g (x, y) <20. I started looking and found the contour tool, with which I could graph the region of R ^ 2 where f (x, y) = 9, f (x, y) = 8, … and so on in such a way as to is making a sketch of the region that I want. And then analogously with g. I was liking the way it looked but I didn’t like Warning’s message, which I now know was really useful, thanks to one of you.
I still can’t find the tool I’m telling you.
But I have improved a bit in the use of contour.
It seems to be better to have a proper software warning than a poor plot?
Living with the warning we can get plots for the intersection of f(x,y)<10 with g(x,y)<20, like:
or like:
NB: The zero contour level is an abstraction to indicate the intersection of the functions’ surfaces themselves.
using Plots;gr()
f(x,y) = x + y - 2
g(x,y) = x - y - 1
θ(x,y) = (f(x,y) < 10) & (g(x,y) < 20 ) ? 1 : NaN
x = y = LinRange(-30,30,1000)
heatmap(x,y,θ, c=:lightblue, legend=false, ratio=1, xlims=extrema(x),ylims=extrema(y))