Forum Discussion

NicoBoss's avatar
NicoBoss
New Member
1 year ago
Solved

Overlaying graphs with independant tables using python or ...

Good day, 

I have 2 independant graphs associated to 2 independant table.

table1 with x1-values y1-values and table2 with x2-values y2-values 

All data are decimals, BUT x1-values do not match x2-values

Is is possible to have the two curve on the same graph ? 

I guess it should be easy but i am struggling

Thank you so much.

 

  • Anonymous's avatar
    Anonymous
    1 year ago

    Hi NicoBoss 

     

    Thank you very much govind_021 for your prompt reply.

     

    If Time1 is not equal to Time2, I suggest you create a bridge table as follows:

     

    “Time1”

     

    "Time2"

     

    Create a new table.

     

    Bridge Table = 
    UNION(
        SELECTCOLUMNS(
            'Table1',
            "Time",
            'Table1'[Time1]),
            SELECTCOLUMNS(
            'Table2',
            "Time",
            'Table2'[Time2])
    )

     

     

    Table1 and Table2 create relationships with the bridge table respectively.

     

     

    Create a Python visual.

     

    import matplotlib.pyplot as plt
    
    # Create figure and axis
    ax = plt.gca()
    
    dataset.plot(kind= "line", x='Time1', y='Depth1', color= "Red", ax= ax)
    
    dataset.plot(kind= "line", x='Time2', y='Depth2', color= "Blue", ax= ax)
    
    # Show plot
    plt.show()
    

     

    Here is the result.

     

     

    Regards,

    Nono Chen

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

3 Replies

  • Hi NicoBoss 
    Can you give more context to your question by adding images of the problem , if confidential then with dummy data.

    • NicoBoss's avatar
      NicoBoss
      New Member

      Thanks Sure,  I tried the code below. 

      This code is working fine if Time1=Time2, then i can create a table with 3 column only, X=Time1 Y1=Depth1 and Y2=Depth2 and plot 2 curves.

      But Time1≠Time2, also the table1 is not the same size as table2, so I cannot merge and I get the error : "can't display the data because PowerBI can't determine the relationship between two or more fields"

      Indeed they are 2 different tables from 2 different queries. 

      Time1/Depth1 and Time2/Depth2 are from 2 different datatables in the same powerbi, I opened a Py-Python Visual, draged and droped those tables in the "Values" field. 

      Basically just want to overlay 2 curves (without the same dimension), should be easy? I am struggling for more than 1 day... I read it is not so easy in PowerBI DAX but they are ways around, but so far still searching... 

      ---

      import matplotlib.pyplot as plt
      import numpy as np
      f, a = plt.subplots()
      data = dataset
      x1 = data['Time1']
      y1 = data['Depth1']
      x2 = data['Time2']
      y2 = data['Depth2']
      a.plot(x1,y1,'r--')
      a.plot(x2,y2,'--')
      plt.show()
      ---
      • Anonymous's avatar
        Anonymous
        Not applicable

        Hi NicoBoss 

         

        Thank you very much govind_021 for your prompt reply.

         

        If Time1 is not equal to Time2, I suggest you create a bridge table as follows:

         

        “Time1”

         

        "Time2"

         

        Create a new table.

         

        Bridge Table = 
        UNION(
            SELECTCOLUMNS(
                'Table1',
                "Time",
                'Table1'[Time1]),
                SELECTCOLUMNS(
                'Table2',
                "Time",
                'Table2'[Time2])
        )

         

         

        Table1 and Table2 create relationships with the bridge table respectively.

         

         

        Create a Python visual.

         

        import matplotlib.pyplot as plt
        
        # Create figure and axis
        ax = plt.gca()
        
        dataset.plot(kind= "line", x='Time1', y='Depth1', color= "Red", ax= ax)
        
        dataset.plot(kind= "line", x='Time2', y='Depth2', color= "Blue", ax= ax)
        
        # Show plot
        plt.show()
        

         

        Here is the result.

         

         

        Regards,

        Nono Chen

        If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.