Home > Software engineering >  How to plot Multiline Graphs Via Seaborn library in python?
How to plot Multiline Graphs Via Seaborn library in python?

Time:10-04

I have written a code that loos like this:

import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
T = np.array([10.03,100.348,1023.385])
power1 = np.array([100000,86000,73000])
power2 = np.array([1008000,95000,1009000])

df1 = pd.DataFrame(data = {'Size': T, 'Encrypt_Time': power1, 'Decrypt_Time': power2})
exp1= sns.lineplot(data=df1)
plt.savefig('exp1.png')
exp1_smooth= sns.lmplot(x='Size', y='Time', data=df, ci=None, order=4, truncate=False)
plt.savefig('exp1_smooth.png')

That gives me that image: Image attached: Graph_1

The Size = x- axis is a constant line but as you can see in my code it varies from (10,100,1000) How does this produces a constant line? Is there any issue with my code? I want to produce a multiline graph with x-axis = Size(T),y- axis= Encrypt_Time and Decrypt_Time(power1 & power2)

Also I wanted to plot a smooth graph of the same graph I am getting right now but it gives me error. Can anyone help me with this code and tell me what exactly needs to be done in order to achieve a smooth multiline graph with x-axis = Size(T),y- axis= Encrypt_Time and Decrypt_Time(power1 & power2)

CodePudding user response:

I think it not the issue, the line represents for size looks like constant but it NOT.

Can see that values of size in range 10-1000 while the minimum division of y-axis is 20,000 (20 times bigger), make it look like a horizontal line on your graph. You can try with a bigger values to see the slope clearly.

If you want 'size` as x-axis, you can try below example:

import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
T = np.array([10.03,100.348,1023.385])
power1 = np.array([100000,86000,73000])
power2 = np.array([1008000,95000,1009000])

df1 = pd.DataFrame(data = {'Size': T, 'Encrypt_Time': power1, 'Decrypt_Time': power2})
fig = plt.figure()
fig = sns.lineplot(data=df1, x='Size',y='Encrypt_Time' )
fig = sns.lineplot(data=df1, x='Size',y='Decrypt_Time' )
  • Related