0

Using the plot functionality in pandas dataframe I try to get a proper logarithmic x-axis: sample code:

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

fig,ax = plt.subplots()
df = pd.DataFrame({'Freq':[63,125,250,500],'A':[1,2,3,4]})

ax.set_xscale('log')
ax.set_xticks(df['Freq'])
ax.set_xticklabels(df['Freq'])
df.set_index('Freq').plot(ax=ax)

This does however just result in 2 sets of x-ticks.. on top of each other:

logxplot

I have looked at this, changed the order of commands, but that does not change anything. Anyone any ideas....?

EDIT:

I have also tried the following

import pandas as pd 

fig,ax = plt.subplots() df =
pd.DataFrame({'Freq':[63,125,250,500],'A':[1,2,3,4]})
df.plot(ax=ax,x='Freq',logx=True,xticks=df['Freq'])

with almost identical results.

Erik Thysell
  • 1,160
  • 1
  • 14
  • 31

1 Answers1

0

Try using the logx in the Pandas plotting interface directly.

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

fig,ax = plt.subplots()
df = pd.DataFrame({'Freq':[63,125,250,500],'A':[1,2,3,4]})

df.set_index('Freq').plot(ax=ax, logx=True)```
Toukenize
  • 1,390
  • 1
  • 7
  • 11