Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Adding two plots with differnts x start

I’m trying to merge two curves into only one, but the originals two lines are shifted horizontally:

import numpy as np

a = np.array([[1,2,3], # x value
               [0.3, 0.5, 0.6]]) # y value
b = np.array([[2,3,4], [0.5,0.4,0.3]])

I need c = [[1,2,3,4],[0.3, 1, 1, 0.3]]

How can I done?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can use pandas:

import pandas as pd
import numpy as np

a = np.array([[1,2,3], # x value
           [0.3, 0.5, 0.6]]) # y value
b = np.array([[2,3,4], [0.5,0.4,0.3]])

pd.concat(map(pd.DataFrame,[a.T, b.T])).groupby(0).sum().plot()

Output:

enter image description here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading