Plotting with different color for a single curvePlotting piecewise function with distinct colors in each...
Can White Castle?
Can ADFS connect to other SSO services?
Do French speakers not use the subjunctive informally?
How can I get more energy without spending coins?
Are Finite Automata Turing Complete?
Do flight schools typically have dress codes or expectations?
Does squid ink pasta bleed?
Change CPU MHz from Registry
Why is there no havdallah when going from Yom Tov into Shabbat?
What kind of wire should I use to pigtail an outlet?
Should I include salary information on my CV?
Links to webpages in books
Distance Matrix (plugin) - QGIS
Peace Arch without exiting USA
How come I was asked by a CBP officer why I was in the US?
Inverse-quotes-quine
Why do some games show lights shine through walls?
Should I tell my insurance company I'm making payments on my new car?
Is there any evidence that the small canisters (10 liters) of 95% oxygen actually help with altitude sickness?
Story-based adventure with functions and relationships
Smooth Julia set for quadratic polynomials
MH370 blackbox - is it still possible to retrieve data from it?
Unusual mail headers, evidence of an attempted attack. Have I been pwned?
Apply brace expansion in "reverse order"
Plotting with different color for a single curve
Plotting piecewise function with distinct colors in each sectionSubset of edges with a different colorNeed 4D plot (3D + color for function)Question about plotting one function with different colorsWant a different color for each curve displayed with ShowHow to plot data with different colors (or symbols) depending on a conditionListPlot with different color optionsListPlot with different color options part IIPlotting: every point in different colorPlotting a function with different parameters sets
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}
$begingroup$
How to plot a function $f(x)=frac{3(4+x)}{3(2-x)-16}$ (say $x in [-15,15]$ ) with the condition that i want to give different color for each of the following cases
(i) when $frac{x+4}{3x+10}>0$ and $frac{x^2+8x+12}{3x+10}>0$
(ii) when $frac{x+4}{3x+10}>0$ and $frac{x^2+8x+12}{3x+10}<0$
(iii) when $frac{x+4}{3x+10}<0$ and $frac{x^2+8x+12}{3x+10}>0$
plotting
New contributor
$endgroup$
add a comment |
$begingroup$
How to plot a function $f(x)=frac{3(4+x)}{3(2-x)-16}$ (say $x in [-15,15]$ ) with the condition that i want to give different color for each of the following cases
(i) when $frac{x+4}{3x+10}>0$ and $frac{x^2+8x+12}{3x+10}>0$
(ii) when $frac{x+4}{3x+10}>0$ and $frac{x^2+8x+12}{3x+10}<0$
(iii) when $frac{x+4}{3x+10}<0$ and $frac{x^2+8x+12}{3x+10}>0$
plotting
New contributor
$endgroup$
add a comment |
$begingroup$
How to plot a function $f(x)=frac{3(4+x)}{3(2-x)-16}$ (say $x in [-15,15]$ ) with the condition that i want to give different color for each of the following cases
(i) when $frac{x+4}{3x+10}>0$ and $frac{x^2+8x+12}{3x+10}>0$
(ii) when $frac{x+4}{3x+10}>0$ and $frac{x^2+8x+12}{3x+10}<0$
(iii) when $frac{x+4}{3x+10}<0$ and $frac{x^2+8x+12}{3x+10}>0$
plotting
New contributor
$endgroup$
How to plot a function $f(x)=frac{3(4+x)}{3(2-x)-16}$ (say $x in [-15,15]$ ) with the condition that i want to give different color for each of the following cases
(i) when $frac{x+4}{3x+10}>0$ and $frac{x^2+8x+12}{3x+10}>0$
(ii) when $frac{x+4}{3x+10}>0$ and $frac{x^2+8x+12}{3x+10}<0$
(iii) when $frac{x+4}{3x+10}<0$ and $frac{x^2+8x+12}{3x+10}>0$
plotting
plotting
New contributor
New contributor
New contributor
asked 11 hours ago
WomWom
162 bronze badges
162 bronze badges
New contributor
New contributor
add a comment |
add a comment |
4 Answers
4
active
oldest
votes
$begingroup$
Admittedly, not very different from the naïve answer already posted, just avoided repeating the function definitions.
f[x_] := (3 (x + 4))/(3 (2 - x) - 16);
g[x_] := (x + 4)/(3 x + 10);
h[x_] := (x^2 + 8 x + 12)/(3 x + 10);
a[x_] := (g[x] > 0 && h[x] > 0);
b[x_] := (g[x] > 0 && h[x] < 0);
c[x_] := (g[x] < 0 && h[x] > 0);
Plot[{f[x] && a[x], f[x] && b[x], f[x] && c[x]}, {x, -15, 15},
PlotRange -> {-3, 3}, PlotStyle -> Thickness[.01], Frame -> True,
Axes -> False]
$endgroup$
add a comment |
$begingroup$
You could use the option ColorFunction
with ColorFunctionScaling->False
. First your conditions:
cond1[x_] := (x+4)/(3x+10)>0 && (x^2+8x+12)/(3x+10)>0
cond2[x_] := (x+4)/(3x+10)>0 && (x^2+8x+12)/(3x+10)<0
cond3[x_] := (x+4)/(3x+10)<0 && (x^2+8x+12)/(3x+10)>0
And your function:
f[x_] := (3(4+x))/(3(2-x)-16)
Then:
Plot[f[x], {x, -15, 15},
PlotRange -> {All, {-3, 3}},
ColorFunctionScaling -> False,
ColorFunction -> Function @ Piecewise[
{
{ColorData[97][1], cond1[#]},
{ColorData[97][2], cond2[#]},
{ColorData[97][3], cond3[#]}
},
ColorData[97][4]
]
]
$endgroup$
add a comment |
$begingroup$
Naïve solution:
f1[x_] /; And[(x + 4)/(3 x + 10) > 0, (x^2 + 8 x + 12)/(3 x + 10) > 0] := (3 (4 + x))/(3 (2 - x) - 16)
f2[x_] /; And[(x + 4)/(3 x + 10) > 0, (x^2 + 8 x + 12)/(3 x + 10) < 0] := (3 (4 + x))/(3 (2 - x) - 16)
f3[x_] /; And[(x + 4)/(3 x + 10) < 0, (x^2 + 8 x + 12)/(3 x + 10) > 0] := (3 (4 + x))/(3 (2 - x) - 16)
Plot[{f1[x], f2[x], f3[x]}, {x, -15, 15}, PlotRange -> {All, {-10, 10}}]
$endgroup$
add a comment |
$begingroup$
An alternative way to specify a color function:
f[x_] := (3 (4 + x))/(3 (2 - x) - 16)
cf = ColorData[97]@(1 + {1, 2}.UnitStep[{(# + 4)/(3 # + 10), (#^2 + 8 # + 12)/(3 # + 10)}]) &;
Plot[f[x], {x, -15, 15},
PlotRange -> {All, {-3, 3}},
BaseStyle -> AbsoluteThickness[5],
ColorFunction -> cf,
ColorFunctionScaling -> False]
$endgroup$
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "387"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Wom is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f200790%2fplotting-with-different-color-for-a-single-curve%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
Admittedly, not very different from the naïve answer already posted, just avoided repeating the function definitions.
f[x_] := (3 (x + 4))/(3 (2 - x) - 16);
g[x_] := (x + 4)/(3 x + 10);
h[x_] := (x^2 + 8 x + 12)/(3 x + 10);
a[x_] := (g[x] > 0 && h[x] > 0);
b[x_] := (g[x] > 0 && h[x] < 0);
c[x_] := (g[x] < 0 && h[x] > 0);
Plot[{f[x] && a[x], f[x] && b[x], f[x] && c[x]}, {x, -15, 15},
PlotRange -> {-3, 3}, PlotStyle -> Thickness[.01], Frame -> True,
Axes -> False]
$endgroup$
add a comment |
$begingroup$
Admittedly, not very different from the naïve answer already posted, just avoided repeating the function definitions.
f[x_] := (3 (x + 4))/(3 (2 - x) - 16);
g[x_] := (x + 4)/(3 x + 10);
h[x_] := (x^2 + 8 x + 12)/(3 x + 10);
a[x_] := (g[x] > 0 && h[x] > 0);
b[x_] := (g[x] > 0 && h[x] < 0);
c[x_] := (g[x] < 0 && h[x] > 0);
Plot[{f[x] && a[x], f[x] && b[x], f[x] && c[x]}, {x, -15, 15},
PlotRange -> {-3, 3}, PlotStyle -> Thickness[.01], Frame -> True,
Axes -> False]
$endgroup$
add a comment |
$begingroup$
Admittedly, not very different from the naïve answer already posted, just avoided repeating the function definitions.
f[x_] := (3 (x + 4))/(3 (2 - x) - 16);
g[x_] := (x + 4)/(3 x + 10);
h[x_] := (x^2 + 8 x + 12)/(3 x + 10);
a[x_] := (g[x] > 0 && h[x] > 0);
b[x_] := (g[x] > 0 && h[x] < 0);
c[x_] := (g[x] < 0 && h[x] > 0);
Plot[{f[x] && a[x], f[x] && b[x], f[x] && c[x]}, {x, -15, 15},
PlotRange -> {-3, 3}, PlotStyle -> Thickness[.01], Frame -> True,
Axes -> False]
$endgroup$
Admittedly, not very different from the naïve answer already posted, just avoided repeating the function definitions.
f[x_] := (3 (x + 4))/(3 (2 - x) - 16);
g[x_] := (x + 4)/(3 x + 10);
h[x_] := (x^2 + 8 x + 12)/(3 x + 10);
a[x_] := (g[x] > 0 && h[x] > 0);
b[x_] := (g[x] > 0 && h[x] < 0);
c[x_] := (g[x] < 0 && h[x] > 0);
Plot[{f[x] && a[x], f[x] && b[x], f[x] && c[x]}, {x, -15, 15},
PlotRange -> {-3, 3}, PlotStyle -> Thickness[.01], Frame -> True,
Axes -> False]
answered 10 hours ago
mjwmjw
1,37510 bronze badges
1,37510 bronze badges
add a comment |
add a comment |
$begingroup$
You could use the option ColorFunction
with ColorFunctionScaling->False
. First your conditions:
cond1[x_] := (x+4)/(3x+10)>0 && (x^2+8x+12)/(3x+10)>0
cond2[x_] := (x+4)/(3x+10)>0 && (x^2+8x+12)/(3x+10)<0
cond3[x_] := (x+4)/(3x+10)<0 && (x^2+8x+12)/(3x+10)>0
And your function:
f[x_] := (3(4+x))/(3(2-x)-16)
Then:
Plot[f[x], {x, -15, 15},
PlotRange -> {All, {-3, 3}},
ColorFunctionScaling -> False,
ColorFunction -> Function @ Piecewise[
{
{ColorData[97][1], cond1[#]},
{ColorData[97][2], cond2[#]},
{ColorData[97][3], cond3[#]}
},
ColorData[97][4]
]
]
$endgroup$
add a comment |
$begingroup$
You could use the option ColorFunction
with ColorFunctionScaling->False
. First your conditions:
cond1[x_] := (x+4)/(3x+10)>0 && (x^2+8x+12)/(3x+10)>0
cond2[x_] := (x+4)/(3x+10)>0 && (x^2+8x+12)/(3x+10)<0
cond3[x_] := (x+4)/(3x+10)<0 && (x^2+8x+12)/(3x+10)>0
And your function:
f[x_] := (3(4+x))/(3(2-x)-16)
Then:
Plot[f[x], {x, -15, 15},
PlotRange -> {All, {-3, 3}},
ColorFunctionScaling -> False,
ColorFunction -> Function @ Piecewise[
{
{ColorData[97][1], cond1[#]},
{ColorData[97][2], cond2[#]},
{ColorData[97][3], cond3[#]}
},
ColorData[97][4]
]
]
$endgroup$
add a comment |
$begingroup$
You could use the option ColorFunction
with ColorFunctionScaling->False
. First your conditions:
cond1[x_] := (x+4)/(3x+10)>0 && (x^2+8x+12)/(3x+10)>0
cond2[x_] := (x+4)/(3x+10)>0 && (x^2+8x+12)/(3x+10)<0
cond3[x_] := (x+4)/(3x+10)<0 && (x^2+8x+12)/(3x+10)>0
And your function:
f[x_] := (3(4+x))/(3(2-x)-16)
Then:
Plot[f[x], {x, -15, 15},
PlotRange -> {All, {-3, 3}},
ColorFunctionScaling -> False,
ColorFunction -> Function @ Piecewise[
{
{ColorData[97][1], cond1[#]},
{ColorData[97][2], cond2[#]},
{ColorData[97][3], cond3[#]}
},
ColorData[97][4]
]
]
$endgroup$
You could use the option ColorFunction
with ColorFunctionScaling->False
. First your conditions:
cond1[x_] := (x+4)/(3x+10)>0 && (x^2+8x+12)/(3x+10)>0
cond2[x_] := (x+4)/(3x+10)>0 && (x^2+8x+12)/(3x+10)<0
cond3[x_] := (x+4)/(3x+10)<0 && (x^2+8x+12)/(3x+10)>0
And your function:
f[x_] := (3(4+x))/(3(2-x)-16)
Then:
Plot[f[x], {x, -15, 15},
PlotRange -> {All, {-3, 3}},
ColorFunctionScaling -> False,
ColorFunction -> Function @ Piecewise[
{
{ColorData[97][1], cond1[#]},
{ColorData[97][2], cond2[#]},
{ColorData[97][3], cond3[#]}
},
ColorData[97][4]
]
]
answered 10 hours ago
Carl WollCarl Woll
85.1k3 gold badges109 silver badges220 bronze badges
85.1k3 gold badges109 silver badges220 bronze badges
add a comment |
add a comment |
$begingroup$
Naïve solution:
f1[x_] /; And[(x + 4)/(3 x + 10) > 0, (x^2 + 8 x + 12)/(3 x + 10) > 0] := (3 (4 + x))/(3 (2 - x) - 16)
f2[x_] /; And[(x + 4)/(3 x + 10) > 0, (x^2 + 8 x + 12)/(3 x + 10) < 0] := (3 (4 + x))/(3 (2 - x) - 16)
f3[x_] /; And[(x + 4)/(3 x + 10) < 0, (x^2 + 8 x + 12)/(3 x + 10) > 0] := (3 (4 + x))/(3 (2 - x) - 16)
Plot[{f1[x], f2[x], f3[x]}, {x, -15, 15}, PlotRange -> {All, {-10, 10}}]
$endgroup$
add a comment |
$begingroup$
Naïve solution:
f1[x_] /; And[(x + 4)/(3 x + 10) > 0, (x^2 + 8 x + 12)/(3 x + 10) > 0] := (3 (4 + x))/(3 (2 - x) - 16)
f2[x_] /; And[(x + 4)/(3 x + 10) > 0, (x^2 + 8 x + 12)/(3 x + 10) < 0] := (3 (4 + x))/(3 (2 - x) - 16)
f3[x_] /; And[(x + 4)/(3 x + 10) < 0, (x^2 + 8 x + 12)/(3 x + 10) > 0] := (3 (4 + x))/(3 (2 - x) - 16)
Plot[{f1[x], f2[x], f3[x]}, {x, -15, 15}, PlotRange -> {All, {-10, 10}}]
$endgroup$
add a comment |
$begingroup$
Naïve solution:
f1[x_] /; And[(x + 4)/(3 x + 10) > 0, (x^2 + 8 x + 12)/(3 x + 10) > 0] := (3 (4 + x))/(3 (2 - x) - 16)
f2[x_] /; And[(x + 4)/(3 x + 10) > 0, (x^2 + 8 x + 12)/(3 x + 10) < 0] := (3 (4 + x))/(3 (2 - x) - 16)
f3[x_] /; And[(x + 4)/(3 x + 10) < 0, (x^2 + 8 x + 12)/(3 x + 10) > 0] := (3 (4 + x))/(3 (2 - x) - 16)
Plot[{f1[x], f2[x], f3[x]}, {x, -15, 15}, PlotRange -> {All, {-10, 10}}]
$endgroup$
Naïve solution:
f1[x_] /; And[(x + 4)/(3 x + 10) > 0, (x^2 + 8 x + 12)/(3 x + 10) > 0] := (3 (4 + x))/(3 (2 - x) - 16)
f2[x_] /; And[(x + 4)/(3 x + 10) > 0, (x^2 + 8 x + 12)/(3 x + 10) < 0] := (3 (4 + x))/(3 (2 - x) - 16)
f3[x_] /; And[(x + 4)/(3 x + 10) < 0, (x^2 + 8 x + 12)/(3 x + 10) > 0] := (3 (4 + x))/(3 (2 - x) - 16)
Plot[{f1[x], f2[x], f3[x]}, {x, -15, 15}, PlotRange -> {All, {-10, 10}}]
answered 11 hours ago
AccidentalFourierTransformAccidentalFourierTransform
5,6051 gold badge11 silver badges42 bronze badges
5,6051 gold badge11 silver badges42 bronze badges
add a comment |
add a comment |
$begingroup$
An alternative way to specify a color function:
f[x_] := (3 (4 + x))/(3 (2 - x) - 16)
cf = ColorData[97]@(1 + {1, 2}.UnitStep[{(# + 4)/(3 # + 10), (#^2 + 8 # + 12)/(3 # + 10)}]) &;
Plot[f[x], {x, -15, 15},
PlotRange -> {All, {-3, 3}},
BaseStyle -> AbsoluteThickness[5],
ColorFunction -> cf,
ColorFunctionScaling -> False]
$endgroup$
add a comment |
$begingroup$
An alternative way to specify a color function:
f[x_] := (3 (4 + x))/(3 (2 - x) - 16)
cf = ColorData[97]@(1 + {1, 2}.UnitStep[{(# + 4)/(3 # + 10), (#^2 + 8 # + 12)/(3 # + 10)}]) &;
Plot[f[x], {x, -15, 15},
PlotRange -> {All, {-3, 3}},
BaseStyle -> AbsoluteThickness[5],
ColorFunction -> cf,
ColorFunctionScaling -> False]
$endgroup$
add a comment |
$begingroup$
An alternative way to specify a color function:
f[x_] := (3 (4 + x))/(3 (2 - x) - 16)
cf = ColorData[97]@(1 + {1, 2}.UnitStep[{(# + 4)/(3 # + 10), (#^2 + 8 # + 12)/(3 # + 10)}]) &;
Plot[f[x], {x, -15, 15},
PlotRange -> {All, {-3, 3}},
BaseStyle -> AbsoluteThickness[5],
ColorFunction -> cf,
ColorFunctionScaling -> False]
$endgroup$
An alternative way to specify a color function:
f[x_] := (3 (4 + x))/(3 (2 - x) - 16)
cf = ColorData[97]@(1 + {1, 2}.UnitStep[{(# + 4)/(3 # + 10), (#^2 + 8 # + 12)/(3 # + 10)}]) &;
Plot[f[x], {x, -15, 15},
PlotRange -> {All, {-3, 3}},
BaseStyle -> AbsoluteThickness[5],
ColorFunction -> cf,
ColorFunctionScaling -> False]
answered 1 hour ago
kglrkglr
200k10 gold badges229 silver badges455 bronze badges
200k10 gold badges229 silver badges455 bronze badges
add a comment |
add a comment |
Wom is a new contributor. Be nice, and check out our Code of Conduct.
Wom is a new contributor. Be nice, and check out our Code of Conduct.
Wom is a new contributor. Be nice, and check out our Code of Conduct.
Wom is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Mathematica Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f200790%2fplotting-with-different-color-for-a-single-curve%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown