Python Forum
Creating Complex Color Spectrum Plot From Data
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Creating Complex Color Spectrum Plot From Data
#1
Hello all

I was hoping I could get some suggestions on how to implement the following Python program.

I work on the highway, one of the issues I have to deal with is fixing surface cracks.

The only time I need to intervene is when there are at least 4 cracks on the same cross section. For example, the attachment P1 shows 5 lines, each line represents a crack. In this case all 5 of these cracks were found between 2m and 6m.

See P1 Attachment

However I only need to intervene when 4 or more of the cracks overlap, as shown below.
From attachment P2 you can see that there are 4 cracks the all overlap between 3.7m and 4.2m – it is this section that I need to fix.

See P2 Attachment

My aim is to create a color spectrum where if there is no cracks then the color of the row /plot would be green, if it has 2 x overlapping cracks then the color would be yellow, 3 over lapping cracks the color would be Red and 4 or more overlapping cracks the color would be light blue. For example:-

See P3 Attachment

This is what I wanted to create in Python.
For a new user I know this is a challenging task but I am up to it.
But I wanted to ask if this was possible? I was considering achieving this in a figure window with a plot?

But is there an alternative way to do this? I have the data that tells me where the cracks start and stop i.e.
Crack Type Start Stop
A 5.128 5.962
A 5.965 7.123

Is there a built in function where if I ordered the data in some way then Python/Matplot lib could some how achieve my objective?

Any help or advice would be greatly appreciated.

Thank you.

Attached Files

Thumbnail(s)
           
Reply
#2
By counting +1 for a crack start and -1 for a crack stop, you can easily determine the number of cracks at any position. Here is an example
cracks = [
    (3.69, 4.37),
    (3.37, 4.63),
    (3.74, 5.57),
    (2.66, 4.34),
    (4.11, 5.77)
]

def main():
    L = []
    for start, stop in cracks:
        L.append((start, 1))
        L.append((stop, -1))
    L.sort()
    s = 0
    for i, (x, incr) in enumerate(L):
        s += incr
        L[i] = (x, s)
    
    print(L)
    print()
    u, v = zip(*L)
    print(u)
    print(v)
        

if __name__ == '__main__':
    main()
The output shows clearly that there are at least 4 cracks between 3.74 meters and 4.37
Output:
[(2.66, 1), (3.37, 2), (3.69, 3), (3.74, 4), (4.11, 5), (4.34, 4), (4.37, 3), (4.63, 2), (5.57, 1), (5.77, 0)] (2.66, 3.37, 3.69, 3.74, 4.11, 4.34, 4.37, 4.63, 5.57, 5.77) (1, 2, 3, 4, 5, 4, 3, 2, 1, 0)
Reply
#3
If I borrow Gribouillis' cracks[] (no pun intended), and multiply them by 100, to get centimeters,
I can put them in a 600(cm) by 5 matrix. For me it is easier to set the matrix to 0 when no crack,
series of "1" indicate a crack. Numpy tells me the sum of the 5 rows. (This varies between 0 = green and 5 = blue)
The simplest of graphics packages (Turtle) turns this in a spectrum plot. No need for "complex" things :-)
Paul

[Image: cracks.jpg]
It is more important to do the right thing, than to do the thing right.(P.Drucker)
Better is the enemy of good. (Montesquieu) = French version for 'kiss'.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Turtle Star Fill Color Yellow-White Interchanging Color Effect codelab 9 903 Oct-25-2023, 09:09 AM
Last Post: codelab
  Likert survey data plot error Andrzej_Andrzej 6 1,307 Jul-16-2023, 10:11 PM
Last Post: deanhystad
  Plot a pandas data fram via pyqtgraph with an modul import and qt designer widget Nietzsche 0 802 May-29-2023, 02:42 PM
Last Post: Nietzsche
  Create simple live plot of stock data dram 2 2,859 Jan-27-2023, 04:34 AM
Last Post: CucumberNox
Thumbs Up Python 3 Jupyter notebook ternary plot data nicholas 0 897 Jan-21-2023, 05:01 PM
Last Post: nicholas
  I need help parsing through data and creating a database using beautiful soup username369 1 1,688 Sep-22-2021, 08:45 PM
Last Post: Larz60+
  Plot data from CSV allen04 2 2,343 Jan-03-2021, 10:30 AM
Last Post: Axel_Erfurt
  How to plot intraday data of several days in one plot mistermister 3 2,855 Dec-15-2020, 07:43 PM
Last Post: deanhystad
  How can I scroll over my data points when creating plots in Python? (I'm using Spyder moose 0 1,582 Nov-02-2020, 07:18 AM
Last Post: moose
  Binding Complex data to Combobox gcfernando 2 2,031 Sep-14-2020, 03:24 PM
Last Post: gcfernando

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020