How to plot a line and set the color of every line in a nested list?How do I check if a list is empty?How can I safely create a nested directory?How do you split a list into evenly sized chunks?How do I break out of nested loops in Java?How to make a flat list out of list of listsHow do I get the number of elements in a list?How do I concatenate two lists in Python?How to clone or copy a list?How do I list all files of a directory?How to read a file line-by-line into a list?
Storming Area 51
Is purchasing foreign currency before going abroad a losing proposition?
Print the last, middle and first character of your code
Supporting developers who insist on using their pet language
Machine learning and operations research projects
What does "it kind of works out" mean?
Professor falsely accusing me of cheating in a class he does not teach, two months after end of the class. What precautions should I take?
Single word for "refusing to move to next activity unless present one is completed."
Are neural networks prone to catastrophic forgetting?
The monorail explodes before I can get on it
What is this welding tool I found in my attic?
Why isn't there research to build a standard lunar, or Martian mobility platform?
Was lunar module "pilot" Harrison Schmitt legally a "pilot" at the time?
Is an acid a salt? Why (not)?
How to achieve this rough borders and stippled illustration look?
How can I get a player to accept that they should stop trying to pull stunts without thinking them through first?
How did the hit man miss?
What explains 9 speed cassettes price differences?
references on the empirical study on the practice of OR
Can I call 112 to check a police officer's identity in the Czech Republic?
Did any of the founding fathers anticipate Lysander Spooner's criticism of the constitution?
Book where the stars go black due to aliens stopping human observation collapsing quantum possibilities
Should I intentionally omit previous work experience when applying for jobs?
What's the minimum number of sensors for a hobby GPS waypoint-following UAV?
How to plot a line and set the color of every line in a nested list?
How do I check if a list is empty?How can I safely create a nested directory?How do you split a list into evenly sized chunks?How do I break out of nested loops in Java?How to make a flat list out of list of listsHow do I get the number of elements in a list?How do I concatenate two lists in Python?How to clone or copy a list?How do I list all files of a directory?How to read a file line-by-line into a list?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I had a nested list and a function:
a = [[2,3,4],[3,4,5],[5,7]]
def triple(a):
return (a**2)+3
I tried to plot every point in the sublist like the first value connected to second, the second connected to the third and stop at the last value in the sublist. x
is the value in the sublist, y
is triple(y for y in sublist)
for g in a:
for t in g:
plt.scatter(t, triple(t))
for g in a:
for o in range(len(g)):
plt.plot([g[o],g[o+1]], [triple(g[o]), triple(g[o+1])], color = 'red')
plt.show()
I tried this but it didn't get the desire output I wanted.
What should I do to plot every sublist in a
and get three different colors of line?
python list loops matplotlib
add a comment |
I had a nested list and a function:
a = [[2,3,4],[3,4,5],[5,7]]
def triple(a):
return (a**2)+3
I tried to plot every point in the sublist like the first value connected to second, the second connected to the third and stop at the last value in the sublist. x
is the value in the sublist, y
is triple(y for y in sublist)
for g in a:
for t in g:
plt.scatter(t, triple(t))
for g in a:
for o in range(len(g)):
plt.plot([g[o],g[o+1]], [triple(g[o]), triple(g[o+1])], color = 'red')
plt.show()
I tried this but it didn't get the desire output I wanted.
What should I do to plot every sublist in a
and get three different colors of line?
python list loops matplotlib
Does this achieve what you want:for sublist in a: plt.plot(sublist, [triple(s) for s in sublist], 'o-')
?
– SamProell
Mar 26 at 6:23
add a comment |
I had a nested list and a function:
a = [[2,3,4],[3,4,5],[5,7]]
def triple(a):
return (a**2)+3
I tried to plot every point in the sublist like the first value connected to second, the second connected to the third and stop at the last value in the sublist. x
is the value in the sublist, y
is triple(y for y in sublist)
for g in a:
for t in g:
plt.scatter(t, triple(t))
for g in a:
for o in range(len(g)):
plt.plot([g[o],g[o+1]], [triple(g[o]), triple(g[o+1])], color = 'red')
plt.show()
I tried this but it didn't get the desire output I wanted.
What should I do to plot every sublist in a
and get three different colors of line?
python list loops matplotlib
I had a nested list and a function:
a = [[2,3,4],[3,4,5],[5,7]]
def triple(a):
return (a**2)+3
I tried to plot every point in the sublist like the first value connected to second, the second connected to the third and stop at the last value in the sublist. x
is the value in the sublist, y
is triple(y for y in sublist)
for g in a:
for t in g:
plt.scatter(t, triple(t))
for g in a:
for o in range(len(g)):
plt.plot([g[o],g[o+1]], [triple(g[o]), triple(g[o+1])], color = 'red')
plt.show()
I tried this but it didn't get the desire output I wanted.
What should I do to plot every sublist in a
and get three different colors of line?
python list loops matplotlib
python list loops matplotlib
asked Mar 26 at 3:20
wayne64001wayne64001
688 bronze badges
688 bronze badges
Does this achieve what you want:for sublist in a: plt.plot(sublist, [triple(s) for s in sublist], 'o-')
?
– SamProell
Mar 26 at 6:23
add a comment |
Does this achieve what you want:for sublist in a: plt.plot(sublist, [triple(s) for s in sublist], 'o-')
?
– SamProell
Mar 26 at 6:23
Does this achieve what you want:
for sublist in a: plt.plot(sublist, [triple(s) for s in sublist], 'o-')
?– SamProell
Mar 26 at 6:23
Does this achieve what you want:
for sublist in a: plt.plot(sublist, [triple(s) for s in sublist], 'o-')
?– SamProell
Mar 26 at 6:23
add a comment |
1 Answer
1
active
oldest
votes
- You specified
color='red'
so every your line is drawn with one color. - You use
plt.scatter
to draw circles. There is no need to do it, you can usemarker
parameter inplt.plot
. - Your code is throwing a
ValueError
because wheno
is in the last element ofg
,o+1
will point to the undefined element. I rewrote this line.
I changed a
a bit, just for a more distinguished view. Here is the final code:
a = [[2, 3, 4], [5, 6, 7], [8, 9]]
for g in a:
plt.plot(g, [(x**2)+3 for x in g], marker='.')
plt.show()
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
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: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
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
);
);
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%2fstackoverflow.com%2fquestions%2f55349370%2fhow-to-plot-a-line-and-set-the-color-of-every-line-in-a-nested-list%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
- You specified
color='red'
so every your line is drawn with one color. - You use
plt.scatter
to draw circles. There is no need to do it, you can usemarker
parameter inplt.plot
. - Your code is throwing a
ValueError
because wheno
is in the last element ofg
,o+1
will point to the undefined element. I rewrote this line.
I changed a
a bit, just for a more distinguished view. Here is the final code:
a = [[2, 3, 4], [5, 6, 7], [8, 9]]
for g in a:
plt.plot(g, [(x**2)+3 for x in g], marker='.')
plt.show()
add a comment |
- You specified
color='red'
so every your line is drawn with one color. - You use
plt.scatter
to draw circles. There is no need to do it, you can usemarker
parameter inplt.plot
. - Your code is throwing a
ValueError
because wheno
is in the last element ofg
,o+1
will point to the undefined element. I rewrote this line.
I changed a
a bit, just for a more distinguished view. Here is the final code:
a = [[2, 3, 4], [5, 6, 7], [8, 9]]
for g in a:
plt.plot(g, [(x**2)+3 for x in g], marker='.')
plt.show()
add a comment |
- You specified
color='red'
so every your line is drawn with one color. - You use
plt.scatter
to draw circles. There is no need to do it, you can usemarker
parameter inplt.plot
. - Your code is throwing a
ValueError
because wheno
is in the last element ofg
,o+1
will point to the undefined element. I rewrote this line.
I changed a
a bit, just for a more distinguished view. Here is the final code:
a = [[2, 3, 4], [5, 6, 7], [8, 9]]
for g in a:
plt.plot(g, [(x**2)+3 for x in g], marker='.')
plt.show()
- You specified
color='red'
so every your line is drawn with one color. - You use
plt.scatter
to draw circles. There is no need to do it, you can usemarker
parameter inplt.plot
. - Your code is throwing a
ValueError
because wheno
is in the last element ofg
,o+1
will point to the undefined element. I rewrote this line.
I changed a
a bit, just for a more distinguished view. Here is the final code:
a = [[2, 3, 4], [5, 6, 7], [8, 9]]
for g in a:
plt.plot(g, [(x**2)+3 for x in g], marker='.')
plt.show()
answered Mar 26 at 15:07
vurmuxvurmux
5,6532 gold badges9 silver badges31 bronze badges
5,6532 gold badges9 silver badges31 bronze badges
add a comment |
add a comment |
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Thanks for contributing an answer to Stack Overflow!
- 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.
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%2fstackoverflow.com%2fquestions%2f55349370%2fhow-to-plot-a-line-and-set-the-color-of-every-line-in-a-nested-list%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
Does this achieve what you want:
for sublist in a: plt.plot(sublist, [triple(s) for s in sublist], 'o-')
?– SamProell
Mar 26 at 6:23