sjdh
sjdh

Reputation: 4016

Log-Log plot of pandas dataframe

I would like to make a log-log plot with pandas

import numpy as np
import pandas as pd
x =  10**arange(1, 10)
y = 10** arange(1,10)*2
df1 = pd.DataFrame( data=y, index=x )
df2 = pd.DataFrame(data = {'x': x, 'y': y})
df1.plot(logy=True, logx=True)    

df1.plot(logy=True, logx=True)

How can I make the x-axis logarithmic?

Upvotes: 12

Views: 30994

Answers (1)

Ffisegydd
Ffisegydd

Reputation: 53728

When trying to create a log-log plot using the pandas plot function you must select loglog=True rather than logx=True, logy=True within your keyword-arguments.

import matplotlib.pyplot as plt 
import pandas as pd
import numpy as np

x = 10 ** np.arange(1, 10)
y = 10 ** np.arange(1, 10) * 2

df1 = pd.DataFrame(data=y, index=x)

df1.plot(loglog=True, legend=False)

plt.show()

Plot

Upvotes: 17

Related Questions