Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Log-Log plot of pandas dataframe

Tags:

python

pandas

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?

like image 973
sjdh Avatar asked May 28 '14 13:05

sjdh


People also ask

What is pandas Dataframe plot()?

Introduction to Pandas DataFrame.plot () The following article provides an outline for Pandas DataFrame.plot (). On top of extensive data processing the need for data reporting is also among the major factors that drive the data world. For achieving data reporting process from pandas perspective the plot () method in pandas library is used.

Is it possible to use math log10 with pandas Dataframe?

From what it seems math.log10 cannot handle neither pandas dataframes nor ndarrays. So one option would be to go with numpy, which also includes a function to compute the base 10 logarithm, np.log10, and reconstruct the dataframe as pointed out in other solutions.

How to find natural logarithmic value of a column in pandas?

Natural logarithmic value of a column in pandas: To find the natural logarithmic values we can apply numpy.log () function to the columns. In this case, we will be finding the natural logarithm values of the column salary. The computed values are stored in the new column “natural_log”.

How to plot a line chart using PANDAS?

Let’s now see the steps to plot a line chart using Pandas. To start, prepare your data for the line chart. Here is an example of a dataset that captures the unemployment rate over time: Now create the DataFrame based on the above data: This is how the DataFrame would look like: Finally, plot the DataFrame by adding the following syntax:


1 Answers

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

like image 187
Ffisegydd Avatar answered Oct 22 '22 22:10

Ffisegydd