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;








1















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?










share|improve this question






















  • 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


















1















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?










share|improve this question






















  • 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














1












1








1








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?










share|improve this question














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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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


















  • 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













1 Answer
1






active

oldest

votes


















0














  1. You specified color='red' so every your line is drawn with one color.

  2. You use plt.scatter to draw circles. There is no need to do it, you can use marker parameter in plt.plot.

  3. Your code is throwing a ValueError because when o is in the last element of g, 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()





share|improve this answer






















    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
    );



    );













    draft saved

    draft discarded


















    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









    0














    1. You specified color='red' so every your line is drawn with one color.

    2. You use plt.scatter to draw circles. There is no need to do it, you can use marker parameter in plt.plot.

    3. Your code is throwing a ValueError because when o is in the last element of g, 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()





    share|improve this answer



























      0














      1. You specified color='red' so every your line is drawn with one color.

      2. You use plt.scatter to draw circles. There is no need to do it, you can use marker parameter in plt.plot.

      3. Your code is throwing a ValueError because when o is in the last element of g, 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()





      share|improve this answer

























        0












        0








        0







        1. You specified color='red' so every your line is drawn with one color.

        2. You use plt.scatter to draw circles. There is no need to do it, you can use marker parameter in plt.plot.

        3. Your code is throwing a ValueError because when o is in the last element of g, 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()





        share|improve this answer













        1. You specified color='red' so every your line is drawn with one color.

        2. You use plt.scatter to draw circles. There is no need to do it, you can use marker parameter in plt.plot.

        3. Your code is throwing a ValueError because when o is in the last element of g, 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()






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 26 at 15:07









        vurmuxvurmux

        5,6532 gold badges9 silver badges31 bronze badges




        5,6532 gold badges9 silver badges31 bronze badges


















            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.



















            draft saved

            draft discarded
















































            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

            Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript