Draw feasible region between constraints (TikZ and pgf) [closed]












2















I'm trying to shade the feasible region ABCDE but for some reason, only get a weird line. This is the code:



begin{tikzpicture}
% axes
begin{axis}[axis on top,smooth,
axis line style=very thick,
axis x line=bottom,
axis y line=left,
ymin=0,ymax=17,xmin=0,xmax=17,
xlabel=$x_1$, ylabel=$x_2$,grid=major
]
% constraints
draw [name path global=xaxis] (0,0) -- (17,0);
draw [name path=yaxis] (0,0) -- (0,17);
addplot[name path global=firstline,very thick, domain=0:17]{6-0.5*x};
addplot[name path global=secondline,very thick, domain=0:17]{3+0.5*x};
addplot[name path global=thirdline,very thick, domain=0:17]{16-2*x};
addplot[name path global=fourthline,very thick, domain=0:17]{7};

% feasible area
fill[name intersections={of=xaxis and yaxis,by=point1},
name intersections={of=secondline and yaxis,by=point2},
name intersections={of=firstline and secondline,by=point3},
name intersections={of=firstline and thirdline,by=point4},
name intersections={of=thirdline and xaxis,by=point5},
][very thick,draw=orange,pattern=crosshatch dots,pattern color=green!60!white](point1)--(point2)--(point3)--(point4)--(point5)--(point1);

% intersection points name
node at (axis cs:0.5,0.7){small{$A$}};
node at (axis cs:0.5,3.9){small{$B$}};
node at (axis cs:3,5.2){small{$C$}};
node at (axis cs:6.8,3.9){small{$D$}};
node at (axis cs:8.2,0.7){small{$E$}};

end{axis}
end{tikzpicture}


enter image description here



Most of the code is taken from one of the responses (cmhughes) here:
How to draw the region of inequality?
Thanks for any insights.



EDIT: Following marmot suggestion, I've added pgfplotsset{compat=1.15} (or whatever version supported) to the preamble and that solved the problem.










share|improve this question















closed as off-topic by CarLaTeX, Stefan Pinnow, Zarko, Kurt, Phelype Oleinik Feb 13 at 20:35



  • This question does not fall within the scope of TeX, LaTeX or related typesetting systems as defined in the help center.

If this question can be reworded to fit the rules in the help center, please edit the question.












  • 5





    Welcome to TeX.SE! I get an area if I compile with the preamble documentclass[tikz,border=3.14mm]{standalone} usepackage{pgfplots} pgfplotsset{compat=1.16} usetikzlibrary{intersections,patterns} begin{document} and of course put end{document} at the end. To understand where your problem comes from, you need to provide the complete preamble, i.e. an MWE.

    – marmot
    Aug 24 '18 at 15:57






  • 1





    If you want to connect A-B-C-D-E, you need to add name intersections={of=firstline and secondline,by=point2a} (which represents C) and add this node to your drawing. Adding --cycle may also help. However, I also cannot reproduce your problem and the area is drawn nicely with marmot’s minimal wrapper.

    – Jasper Habicht
    Aug 24 '18 at 16:34













  • I just rejected an edit by a user with the same name, but different profile picture. May it be that you have two accounts? I've heard that you could merge them. (And if that's really you, I don't understand the comment on version 1.15 vs. 1.16, I get areas in both versions. Or do you just mean that you do not yet have version 1.16?) BTW, I'd be really curious to see the preamble that caused that strange result...

    – marmot
    Aug 24 '18 at 18:57











  • Thanks, just merge the accounts. I am using the exact preamble you suggested. Again, only 1.15 gives me the correct area. I'm using Overleaf v2, perhaps it only uses 1.15? When I go to Overleaf v1 I get an error that I can use maximum 1.14 (which gives me the right area). The main thing is that adding compat command solves the problem. Thanks again.

    – user169054
    Aug 25 '18 at 7:11








  • 4





    I'm voting to close this question as off-topic because solved in comment adding pgfplotsset{compat=1.15}.

    – CarLaTeX
    Feb 13 at 19:57
















2















I'm trying to shade the feasible region ABCDE but for some reason, only get a weird line. This is the code:



begin{tikzpicture}
% axes
begin{axis}[axis on top,smooth,
axis line style=very thick,
axis x line=bottom,
axis y line=left,
ymin=0,ymax=17,xmin=0,xmax=17,
xlabel=$x_1$, ylabel=$x_2$,grid=major
]
% constraints
draw [name path global=xaxis] (0,0) -- (17,0);
draw [name path=yaxis] (0,0) -- (0,17);
addplot[name path global=firstline,very thick, domain=0:17]{6-0.5*x};
addplot[name path global=secondline,very thick, domain=0:17]{3+0.5*x};
addplot[name path global=thirdline,very thick, domain=0:17]{16-2*x};
addplot[name path global=fourthline,very thick, domain=0:17]{7};

% feasible area
fill[name intersections={of=xaxis and yaxis,by=point1},
name intersections={of=secondline and yaxis,by=point2},
name intersections={of=firstline and secondline,by=point3},
name intersections={of=firstline and thirdline,by=point4},
name intersections={of=thirdline and xaxis,by=point5},
][very thick,draw=orange,pattern=crosshatch dots,pattern color=green!60!white](point1)--(point2)--(point3)--(point4)--(point5)--(point1);

% intersection points name
node at (axis cs:0.5,0.7){small{$A$}};
node at (axis cs:0.5,3.9){small{$B$}};
node at (axis cs:3,5.2){small{$C$}};
node at (axis cs:6.8,3.9){small{$D$}};
node at (axis cs:8.2,0.7){small{$E$}};

end{axis}
end{tikzpicture}


enter image description here



Most of the code is taken from one of the responses (cmhughes) here:
How to draw the region of inequality?
Thanks for any insights.



EDIT: Following marmot suggestion, I've added pgfplotsset{compat=1.15} (or whatever version supported) to the preamble and that solved the problem.










share|improve this question















closed as off-topic by CarLaTeX, Stefan Pinnow, Zarko, Kurt, Phelype Oleinik Feb 13 at 20:35



  • This question does not fall within the scope of TeX, LaTeX or related typesetting systems as defined in the help center.

If this question can be reworded to fit the rules in the help center, please edit the question.












  • 5





    Welcome to TeX.SE! I get an area if I compile with the preamble documentclass[tikz,border=3.14mm]{standalone} usepackage{pgfplots} pgfplotsset{compat=1.16} usetikzlibrary{intersections,patterns} begin{document} and of course put end{document} at the end. To understand where your problem comes from, you need to provide the complete preamble, i.e. an MWE.

    – marmot
    Aug 24 '18 at 15:57






  • 1





    If you want to connect A-B-C-D-E, you need to add name intersections={of=firstline and secondline,by=point2a} (which represents C) and add this node to your drawing. Adding --cycle may also help. However, I also cannot reproduce your problem and the area is drawn nicely with marmot’s minimal wrapper.

    – Jasper Habicht
    Aug 24 '18 at 16:34













  • I just rejected an edit by a user with the same name, but different profile picture. May it be that you have two accounts? I've heard that you could merge them. (And if that's really you, I don't understand the comment on version 1.15 vs. 1.16, I get areas in both versions. Or do you just mean that you do not yet have version 1.16?) BTW, I'd be really curious to see the preamble that caused that strange result...

    – marmot
    Aug 24 '18 at 18:57











  • Thanks, just merge the accounts. I am using the exact preamble you suggested. Again, only 1.15 gives me the correct area. I'm using Overleaf v2, perhaps it only uses 1.15? When I go to Overleaf v1 I get an error that I can use maximum 1.14 (which gives me the right area). The main thing is that adding compat command solves the problem. Thanks again.

    – user169054
    Aug 25 '18 at 7:11








  • 4





    I'm voting to close this question as off-topic because solved in comment adding pgfplotsset{compat=1.15}.

    – CarLaTeX
    Feb 13 at 19:57














2












2








2


0






I'm trying to shade the feasible region ABCDE but for some reason, only get a weird line. This is the code:



begin{tikzpicture}
% axes
begin{axis}[axis on top,smooth,
axis line style=very thick,
axis x line=bottom,
axis y line=left,
ymin=0,ymax=17,xmin=0,xmax=17,
xlabel=$x_1$, ylabel=$x_2$,grid=major
]
% constraints
draw [name path global=xaxis] (0,0) -- (17,0);
draw [name path=yaxis] (0,0) -- (0,17);
addplot[name path global=firstline,very thick, domain=0:17]{6-0.5*x};
addplot[name path global=secondline,very thick, domain=0:17]{3+0.5*x};
addplot[name path global=thirdline,very thick, domain=0:17]{16-2*x};
addplot[name path global=fourthline,very thick, domain=0:17]{7};

% feasible area
fill[name intersections={of=xaxis and yaxis,by=point1},
name intersections={of=secondline and yaxis,by=point2},
name intersections={of=firstline and secondline,by=point3},
name intersections={of=firstline and thirdline,by=point4},
name intersections={of=thirdline and xaxis,by=point5},
][very thick,draw=orange,pattern=crosshatch dots,pattern color=green!60!white](point1)--(point2)--(point3)--(point4)--(point5)--(point1);

% intersection points name
node at (axis cs:0.5,0.7){small{$A$}};
node at (axis cs:0.5,3.9){small{$B$}};
node at (axis cs:3,5.2){small{$C$}};
node at (axis cs:6.8,3.9){small{$D$}};
node at (axis cs:8.2,0.7){small{$E$}};

end{axis}
end{tikzpicture}


enter image description here



Most of the code is taken from one of the responses (cmhughes) here:
How to draw the region of inequality?
Thanks for any insights.



EDIT: Following marmot suggestion, I've added pgfplotsset{compat=1.15} (or whatever version supported) to the preamble and that solved the problem.










share|improve this question
















I'm trying to shade the feasible region ABCDE but for some reason, only get a weird line. This is the code:



begin{tikzpicture}
% axes
begin{axis}[axis on top,smooth,
axis line style=very thick,
axis x line=bottom,
axis y line=left,
ymin=0,ymax=17,xmin=0,xmax=17,
xlabel=$x_1$, ylabel=$x_2$,grid=major
]
% constraints
draw [name path global=xaxis] (0,0) -- (17,0);
draw [name path=yaxis] (0,0) -- (0,17);
addplot[name path global=firstline,very thick, domain=0:17]{6-0.5*x};
addplot[name path global=secondline,very thick, domain=0:17]{3+0.5*x};
addplot[name path global=thirdline,very thick, domain=0:17]{16-2*x};
addplot[name path global=fourthline,very thick, domain=0:17]{7};

% feasible area
fill[name intersections={of=xaxis and yaxis,by=point1},
name intersections={of=secondline and yaxis,by=point2},
name intersections={of=firstline and secondline,by=point3},
name intersections={of=firstline and thirdline,by=point4},
name intersections={of=thirdline and xaxis,by=point5},
][very thick,draw=orange,pattern=crosshatch dots,pattern color=green!60!white](point1)--(point2)--(point3)--(point4)--(point5)--(point1);

% intersection points name
node at (axis cs:0.5,0.7){small{$A$}};
node at (axis cs:0.5,3.9){small{$B$}};
node at (axis cs:3,5.2){small{$C$}};
node at (axis cs:6.8,3.9){small{$D$}};
node at (axis cs:8.2,0.7){small{$E$}};

end{axis}
end{tikzpicture}


enter image description here



Most of the code is taken from one of the responses (cmhughes) here:
How to draw the region of inequality?
Thanks for any insights.



EDIT: Following marmot suggestion, I've added pgfplotsset{compat=1.15} (or whatever version supported) to the preamble and that solved the problem.







tikz-pgf pgfplots intersections






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Feb 13 at 20:20









Stefan Pinnow

20k83276




20k83276










asked Aug 24 '18 at 15:51









user169054user169054

132




132




closed as off-topic by CarLaTeX, Stefan Pinnow, Zarko, Kurt, Phelype Oleinik Feb 13 at 20:35



  • This question does not fall within the scope of TeX, LaTeX or related typesetting systems as defined in the help center.

If this question can be reworded to fit the rules in the help center, please edit the question.







closed as off-topic by CarLaTeX, Stefan Pinnow, Zarko, Kurt, Phelype Oleinik Feb 13 at 20:35



  • This question does not fall within the scope of TeX, LaTeX or related typesetting systems as defined in the help center.

If this question can be reworded to fit the rules in the help center, please edit the question.








  • 5





    Welcome to TeX.SE! I get an area if I compile with the preamble documentclass[tikz,border=3.14mm]{standalone} usepackage{pgfplots} pgfplotsset{compat=1.16} usetikzlibrary{intersections,patterns} begin{document} and of course put end{document} at the end. To understand where your problem comes from, you need to provide the complete preamble, i.e. an MWE.

    – marmot
    Aug 24 '18 at 15:57






  • 1





    If you want to connect A-B-C-D-E, you need to add name intersections={of=firstline and secondline,by=point2a} (which represents C) and add this node to your drawing. Adding --cycle may also help. However, I also cannot reproduce your problem and the area is drawn nicely with marmot’s minimal wrapper.

    – Jasper Habicht
    Aug 24 '18 at 16:34













  • I just rejected an edit by a user with the same name, but different profile picture. May it be that you have two accounts? I've heard that you could merge them. (And if that's really you, I don't understand the comment on version 1.15 vs. 1.16, I get areas in both versions. Or do you just mean that you do not yet have version 1.16?) BTW, I'd be really curious to see the preamble that caused that strange result...

    – marmot
    Aug 24 '18 at 18:57











  • Thanks, just merge the accounts. I am using the exact preamble you suggested. Again, only 1.15 gives me the correct area. I'm using Overleaf v2, perhaps it only uses 1.15? When I go to Overleaf v1 I get an error that I can use maximum 1.14 (which gives me the right area). The main thing is that adding compat command solves the problem. Thanks again.

    – user169054
    Aug 25 '18 at 7:11








  • 4





    I'm voting to close this question as off-topic because solved in comment adding pgfplotsset{compat=1.15}.

    – CarLaTeX
    Feb 13 at 19:57














  • 5





    Welcome to TeX.SE! I get an area if I compile with the preamble documentclass[tikz,border=3.14mm]{standalone} usepackage{pgfplots} pgfplotsset{compat=1.16} usetikzlibrary{intersections,patterns} begin{document} and of course put end{document} at the end. To understand where your problem comes from, you need to provide the complete preamble, i.e. an MWE.

    – marmot
    Aug 24 '18 at 15:57






  • 1





    If you want to connect A-B-C-D-E, you need to add name intersections={of=firstline and secondline,by=point2a} (which represents C) and add this node to your drawing. Adding --cycle may also help. However, I also cannot reproduce your problem and the area is drawn nicely with marmot’s minimal wrapper.

    – Jasper Habicht
    Aug 24 '18 at 16:34













  • I just rejected an edit by a user with the same name, but different profile picture. May it be that you have two accounts? I've heard that you could merge them. (And if that's really you, I don't understand the comment on version 1.15 vs. 1.16, I get areas in both versions. Or do you just mean that you do not yet have version 1.16?) BTW, I'd be really curious to see the preamble that caused that strange result...

    – marmot
    Aug 24 '18 at 18:57











  • Thanks, just merge the accounts. I am using the exact preamble you suggested. Again, only 1.15 gives me the correct area. I'm using Overleaf v2, perhaps it only uses 1.15? When I go to Overleaf v1 I get an error that I can use maximum 1.14 (which gives me the right area). The main thing is that adding compat command solves the problem. Thanks again.

    – user169054
    Aug 25 '18 at 7:11








  • 4





    I'm voting to close this question as off-topic because solved in comment adding pgfplotsset{compat=1.15}.

    – CarLaTeX
    Feb 13 at 19:57








5




5





Welcome to TeX.SE! I get an area if I compile with the preamble documentclass[tikz,border=3.14mm]{standalone} usepackage{pgfplots} pgfplotsset{compat=1.16} usetikzlibrary{intersections,patterns} begin{document} and of course put end{document} at the end. To understand where your problem comes from, you need to provide the complete preamble, i.e. an MWE.

– marmot
Aug 24 '18 at 15:57





Welcome to TeX.SE! I get an area if I compile with the preamble documentclass[tikz,border=3.14mm]{standalone} usepackage{pgfplots} pgfplotsset{compat=1.16} usetikzlibrary{intersections,patterns} begin{document} and of course put end{document} at the end. To understand where your problem comes from, you need to provide the complete preamble, i.e. an MWE.

– marmot
Aug 24 '18 at 15:57




1




1





If you want to connect A-B-C-D-E, you need to add name intersections={of=firstline and secondline,by=point2a} (which represents C) and add this node to your drawing. Adding --cycle may also help. However, I also cannot reproduce your problem and the area is drawn nicely with marmot’s minimal wrapper.

– Jasper Habicht
Aug 24 '18 at 16:34







If you want to connect A-B-C-D-E, you need to add name intersections={of=firstline and secondline,by=point2a} (which represents C) and add this node to your drawing. Adding --cycle may also help. However, I also cannot reproduce your problem and the area is drawn nicely with marmot’s minimal wrapper.

– Jasper Habicht
Aug 24 '18 at 16:34















I just rejected an edit by a user with the same name, but different profile picture. May it be that you have two accounts? I've heard that you could merge them. (And if that's really you, I don't understand the comment on version 1.15 vs. 1.16, I get areas in both versions. Or do you just mean that you do not yet have version 1.16?) BTW, I'd be really curious to see the preamble that caused that strange result...

– marmot
Aug 24 '18 at 18:57





I just rejected an edit by a user with the same name, but different profile picture. May it be that you have two accounts? I've heard that you could merge them. (And if that's really you, I don't understand the comment on version 1.15 vs. 1.16, I get areas in both versions. Or do you just mean that you do not yet have version 1.16?) BTW, I'd be really curious to see the preamble that caused that strange result...

– marmot
Aug 24 '18 at 18:57













Thanks, just merge the accounts. I am using the exact preamble you suggested. Again, only 1.15 gives me the correct area. I'm using Overleaf v2, perhaps it only uses 1.15? When I go to Overleaf v1 I get an error that I can use maximum 1.14 (which gives me the right area). The main thing is that adding compat command solves the problem. Thanks again.

– user169054
Aug 25 '18 at 7:11







Thanks, just merge the accounts. I am using the exact preamble you suggested. Again, only 1.15 gives me the correct area. I'm using Overleaf v2, perhaps it only uses 1.15? When I go to Overleaf v1 I get an error that I can use maximum 1.14 (which gives me the right area). The main thing is that adding compat command solves the problem. Thanks again.

– user169054
Aug 25 '18 at 7:11






4




4





I'm voting to close this question as off-topic because solved in comment adding pgfplotsset{compat=1.15}.

– CarLaTeX
Feb 13 at 19:57





I'm voting to close this question as off-topic because solved in comment adding pgfplotsset{compat=1.15}.

– CarLaTeX
Feb 13 at 19:57










0






active

oldest

votes

















0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes

Popular posts from this blog

How to change which sound is reproduced for terminal bell?

Can I use Tabulator js library in my java Spring + Thymeleaf project?

Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents