enable fill between two lines in y direction only within intersection part
This code snippet will plot two lines:
import plotly.graph_objs as go
anchor_rate = [1000, 1660.89, 3220.62, 5927.36]
anchor_psnr = [31.799098, 34.155477, 36.053423, 36.5]
tested_rate = [752.33,1608.90,3114.10,5685.72]
tested_psnr = [31.336015,33.752160,35.730303,37.200365]
fig = go.Figure()
fig.add_trace(go.Scatter(
x=anchor_rate,
y=anchor_psnr,
))
fig.add_trace(go.Scatter(
x=tested_rate,
y=tested_psnr,
))
fig.show()
This is the plot:
How to fill between two lines in y direction only within intersection part, like this? And how can fill them with different colors?
In summary, two questions:
- How to fill between two lines in y direction only within intersection part?
- And how can fill them with different colors?
import plotly.graph_objs as go
anchor_rate = [1000, 1660.89, 3220.62, 5927.36] anchor_psnr = [31.799098, 34.155477, 36.053423, 36.5]
tested_rate = [752.33, 1608.90, 3114.10, 5685.72] tested_psnr = [31.336015, 33.752160, 35.730303, 37.200365]
fig = go.Figure()
fig.add_trace(go.Scatter( x=anchor_rate, y=anchor_psnr, name='Anchor', ))
fig.add_trace(go.Scatter( x=tested_rate, y=tested_psnr, name='Tested', ))
fig.add_trace(go.Scatter( x=anchor_rate + tested_rate[::-1], y=anchor_psnr + tested_psnr[::-1], fill='tozerox', # Fill to the x-axis fillcolor='rgba(0, 100, 80, 0.2)', # Specify fill color line=dict(color='rgba(255,255,255,0)'), # Set line color to transparent showlegend=False, # Hide from legend ))
fig.show()
@sOnU1002 Thanks very much for your reply. But it seems not the expected plots:
- It should only fill the intersection part of the two lines, not beyond them on the left.
- It should fill with the horizontal line, not linking the two end points on the right.
Still thanks for your solution.
ook will try also if any update i will let u know
On Thu, 31 Aug 2023 at 21:57, Longshan Du @.***> wrote:
@sOnU1002 https://github.com/sOnU1002 Thanks very much for your reply. But it seems not the expected plots:
- It should only fill the intersection part of the two lines, not beyond them on the left.
- It should fill with the horizontal line, not linking the two end points on the right. Still thanks for your solution.
[image: image] https://user-images.githubusercontent.com/7447401/264710797-f493508c-650a-4d2c-bfdb-4f40e09aabef.png
— Reply to this email directly, view it on GitHub https://github.com/plotly/plotly.py/issues/4311#issuecomment-1701370512, or unsubscribe https://github.com/notifications/unsubscribe-auth/A3A4AH3RFY7FW7TY74K3NZDXYC3N3ANCNFSM6AAAAAA3E4YSW4 . You are receiving this because you were mentioned.Message ID: @.***>
You can get the intersection points of the horizontal line with the curve with linear Interpolation.
Thanks, I'll check it out.
On Fri, 1 Sept, 2023, 12:35 pm Longshan Du, @.***> wrote:
You can get the intersection points of the horizontal line with the curve with linear Interpolation. [image: image] https://user-images.githubusercontent.com/7447401/264948294-fbc07627-e6c6-4e25-85fb-39fbf8208baa.png
— Reply to this email directly, view it on GitHub https://github.com/plotly/plotly.py/issues/4311#issuecomment-1702272227, or unsubscribe https://github.com/notifications/unsubscribe-auth/A3A4AH34BMCXZO4DUC64B6LXYGCLVANCNFSM6AAAAAA3E4YSW4 . You are receiving this because you were mentioned.Message ID: @.***>
Hi - we are tidying up stale issues and PRs in Plotly's public repositories so that we can focus on things that are still important to our community. Since this one has been sitting for a while, I'm going to close it; if it is still a concern, please add a comment letting us know what recent version of our software you've checked it with so that I can reopen it and add it to our backlog. If you'd like to submit a PR, we'd be happy to prioritize a review, and if it's a request for tech support, please post in our community forum. Thank you - @gvwilson
Please sir don't close it
On Thu, 11 Jul, 2024, 11:02 pm Greg Wilson, @.***> wrote:
Hi - we are tidying up stale issues and PRs in Plotly's public repositories so that we can focus on things that are still important to our community. Since this one has been sitting for a while, I'm going to close it; if it is still a concern, please add a comment letting us know what recent version of our software you've checked it with so that I can reopen it and add it to our backlog. If you'd like to submit a PR, we'd be happy to prioritize a review, and if it's a request for tech support, please post in our community forum. Thank you - @gvwilson https://github.com/gvwilson
— Reply to this email directly, view it on GitHub https://github.com/plotly/plotly.py/issues/4311#issuecomment-2223504674, or unsubscribe https://github.com/notifications/unsubscribe-auth/A3A4AH7DKQMODEZP4NDMGUDZL26SBAVCNFSM6AAAAABKXNUUMGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEMRTGUYDINRXGQ . You are receiving this because you were mentioned.Message ID: @.***>
Give me some if update u regarding it
On Thu, 11 Jul, 2024, 11:16 pm Saket Nigam, @.***> wrote:
Please sir don't close it
On Thu, 11 Jul, 2024, 11:02 pm Greg Wilson, @.***> wrote:
Hi - we are tidying up stale issues and PRs in Plotly's public repositories so that we can focus on things that are still important to our community. Since this one has been sitting for a while, I'm going to close it; if it is still a concern, please add a comment letting us know what recent version of our software you've checked it with so that I can reopen it and add it to our backlog. If you'd like to submit a PR, we'd be happy to prioritize a review, and if it's a request for tech support, please post in our community forum. Thank you - @gvwilson https://github.com/gvwilson
— Reply to this email directly, view it on GitHub https://github.com/plotly/plotly.py/issues/4311#issuecomment-2223504674, or unsubscribe https://github.com/notifications/unsubscribe-auth/A3A4AH7DKQMODEZP4NDMGUDZL26SBAVCNFSM6AAAAABKXNUUMGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEMRTGUYDINRXGQ . You are receiving this because you were mentioned.Message ID: @.***>
Thanks @sOnU1002 - I'll reopen this and add it to our backlog, but realistically, nobody is going to be able to address it any time soon.
Sure
On Fri, 12 Jul, 2024, 5:19 am Greg Wilson, @.***> wrote:
Thanks @sOnU1002 https://github.com/sOnU1002 - I'll reopen this and add it to our backlog, but realistically, nobody is going to be able to address it any time soon.
— Reply to this email directly, view it on GitHub https://github.com/plotly/plotly.py/issues/4311#issuecomment-2224129176, or unsubscribe https://github.com/notifications/unsubscribe-auth/A3A4AHYP2ATYLW3NTTHBNUDZL4KYDAVCNFSM6AAAAABKXNUUMGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEMRUGEZDSMJXGY . You are receiving this because you were mentioned.Message ID: @.***>
import numpy as np import plotly.graph_objs as go
anchor_rate = np.array([1000, 1660.89, 3220.62, 5927.36]) anchor_psnr = np.array([31.799098, 34.155477, 36.053423, 36.5])
tested_rate = np.array([752.33, 1608.90, 3114.10, 5685.72]) tested_psnr = np.array([31.336015, 33.752160, 35.730303, 37.200365])
intersection_x = np.linspace(max(min(anchor_rate), min(tested_rate)), min(max(anchor_rate), max(tested_rate)), 500) intersection_y1 = np.interp(intersection_x, anchor_rate, anchor_psnr) intersection_y2 = np.interp(intersection_x, tested_rate, tested_psnr)
fig = go.Figure()
Add the anchor and tested lines
fig.add_trace(go.Scatter( x=anchor_rate, y=anchor_psnr, mode='lines', name='Anchor' ))
fig.add_trace(go.Scatter( x=tested_rate, y=tested_psnr, mode='lines', name='Tested' ))
fig.add_trace(go.Scatter( x=np.concatenate([intersection_x, intersection_x[::-1]]), y=np.concatenate([intersection_y1, intersection_y2[::-1]]), fill='toself', fillcolor='rgba(0, 100, 80, 0.2)', line=dict(color='rgba(255,255,255,0)'), name='Intersection Area' ))
Update layout
fig.update_layout( title='Plot with Filled Intersection Area', xaxis_title='Rate', yaxis_title='PSNR' )
fig.show() please check it once sir