0

graph

I have data belonging to cumulative distribution. But the range of the x-axis depends on the input data. The y-axis is equally divided into 5 segments. I need to find the corresponding X-axis segments to that.

I tried it with the torch quantile as follows

x_segments = torch.quantile(Cumulative_curve, torch.tensor(y_segemts))

Then the obtained x_segments multiply with the x-axis range. but the result is not as expected as shown in the following figure

How can I do this using python?

2 Answers 2

1

I don't have your sample data to test but I used my sample data and tried the following if this could help you

import torch

# Cumulative distribution data
cumulative_curve = torch.tensor([0.1, 0.3, 0.5, 0.7, 0.9])

# Define the number of segments on the y-axis
num_segments = 5

# Calculate the y-axis segment values
y_segments = torch.linspace(0, 1, num_segments + 1)

# Find the corresponding x-axis segments
x_segments = torch.quantile(cumulative_curve, y_segments)

# Multiply the x-axis segments with the desired x-axis range
x_range_min = 0  # Minimum value of the x-axis range
x_range_max = 100  # Maximum value of the x-axis range
x_segments *= (x_range_max - x_range_min)
x_segments += x_range_min

# Print the x-axis segments
for i in range(len(y_segments)):
    print(f"Segment {i+1}: [{x_segments[i]:.2f}, {x_segments[i+1]:.2f}]")
Sign up to request clarification or add additional context in comments.

Comments

0
import matplotlib.pyplot as plt 
import numpy as np 
import torch

# Define your cumulative distribution curve as a list or a tensor
cumulative_curve = [0.1, 0.3, 0.55, 0.8, 1.0]  # Example values
x= [0,1, 2,3, 4]
# Define the corresponding y-axis segments
y_segments = [0.2, 0.4, 0.6, 0.8, 1.0]  # Example values

# Define the maximum value of the x-axis
N = 4 # Example value

# Convert the cumulative curve to a PyTorch tensor
cumulative_curve_tensor = torch.tensor(cumulative_curve)

# Find the corresponding x-axis segments for each scaled y-axis segment

x_seg = np.interp(y_segments, np.array(cumulative_curve ), np.array(x) )




plt.figure()
plt.plot(cumulative_curve_tensor.numpy().T,label = 'tanh-allJ')
for xc in y_segments:
    print('xc = ',xc)
    plt.axhline(y=xc, color='gray', linestyle='--')  

for yc in list(x_seg):
    print('yc= ', yc)
    
    plt.axvline(x=yc, color='gray', linestyle='--')
print("Corresponding x-axis segments:", x_seg)

This code solved my problem. If anybody needs you also can use this one.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.