13

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?

0

1 Answer 1

17

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

Sign up to request clarification or add additional context in comments.

4 Comments

@Ffisgeydd Did you get a log-log plot from my example?
@sjdh Rather than using logx=True, logy=True instead use loglog=True and it works fine :)
@Ffisgeydd Thanks. I'm new to Python Is this documented somewhere? I could not find it in the Pandas documentation. I did find something about loglog plots in the matplotlib documentation, but I don't know how to apply this to a Pandas dataframe.
It is not mentioned in the plot documentation but it is mentioned in a tutorial as I've linked in my answer.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.