Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7564131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T13:50:21+00:00 2026-05-30T13:50:21+00:00

Given coordinates of [1,5,7,3,5,10,3,6,8] for matplotlib.pyplot , how do I highlight or colour different

  • 0

Given coordinates of [1,5,7,3,5,10,3,6,8] for matplotlib.pyplot, how do I highlight or colour different segments of the line. For instance, the coordinates 1-3 ([1,5,7,3]) in the list represent attribute a. How do I colour this bit of the line and mark it in the legend?

Edit: The list in question contains tens of thousands of elements. I’m trying to highlights specific sections of the list. From the answers so far, is it right to assume I must draw each segment one by one? There isn’t a way to say “select line segment from x1 coord to x2 coord, change colour of line”

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T13:50:22+00:00Added an answer on May 30, 2026 at 1:50 pm

    Yes, you need to redraw the line, but you can clip the line so that only the part you are interested in is visible. To do this I create a rectangle covering the area that represents prop (a), then I use this to create a clip_path.

    import matplotlib.pyplot as plt
    from matplotlib.transforms import Bbox
    
    data = [1,5,7,3,5,10,3,6,8]
    X0 = 1
    X1 = 3
    
    plt.plot(data, label='full results')
    # make a rectangle that will be used to crop out everything not prop (a)
    # make sure to use data 'units', so set the transform to transData
    propArect = plt.Rectangle((X0, min(data)), X1, max(data), 
                              transform=plt.gca().transData)
    # save the line so when can set the clip
    line, = plt.plot(data,
             color='yellow',
             linewidth=8,
             alpha=0.5,
             label='Prop (a)',
             )
    line.set_clip_path(propArect)
    
    handles, labels = plt.gca().get_legend_handles_labels()
    plt.legend(handles, labels)
    plt.savefig('highlight.png')
    plt.show()
    

    This results in:
    enter image description here

    When I plotted the line segment, I adjusted the transparent-ness using the alpha keyword, which ranges from 0-1 or transparent to solid. I also made it a thicker line to extend beyond the original results.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a list of more than 15 thousand latitude and longitude coordinates. Given
How to draw line on MapView given coordinates? AFAIK, on iPhone it is possible.
I used google API to get address from given GPS coordinates. But this address
let's say I have some given coordinates x and y for a pixel, how
I need to calculate the distance (in meters and miles) between two coordinates given
Given two geo-coordinates in (latitude,longitude) format, is it possible to find out if they
Given a set of several million points with x,y coordinates, what is the algorithm
I've been given a struct for a 2D triangle with x and y coordinates,
I need to generate a set of coordinates in Erlang. Given one coordinate, say
Is it possible to use given coordinates in order to simulate a click in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.