0

I am trying to convert the log scale in my visuals using the below code. However it is not happening? Any suggestions?

For Example the actual values of 'Population_2011' column are:

states['Population_2011'].head()

State/ UT
State    199581477
State    112372972
State    103804630
State     91347736
State     72597565
Name: Population_2011, dtype: int64


fig, ax = plt.subplots()
for axis in [ax.xaxis, ax.yaxis]:
    axis.set_major_formatter(ScalarFormatter())
ax.bar(states['Name'], states['Population_2011'])
ax.set_ylabel("Population")
ax.set_title('Poulation of States')
ax.set_xticklabels(states.Name, rotation = 90)
plt.show()

enter image description here

for axis in [ax.xaxis, ax.yaxis]:
    axis.set_major_formatter(ScalarFormatter())
df2.plot(kind='hist', subplots=True, density=True, bins=36)
plt.title('India population distribution (2011)')
plt.show()

enter image description here

Srinivas
  • 568
  • 1
  • 4
  • 21
  • What makes you think the scale is logarithmic? – DavidG May 01 '20 at 10:39
  • This might be helpful:[adjusting scilimits](https://stackoverflow.com/questions/53907897/why-doesnt-adjusting-scilimits-in-matplotlib-work-properly) – JohanC May 01 '20 at 11:54
  • @DavidG, I have edited the details, giving the actual values for states['Population_2011]'. These seem to have been converted into log scale in the figures. – Srinivas May 01 '20 at 12:33
  • @DavidG, I mean the actual values are getting converted into 10 to the power equivalents(marked as 'le#' in the figures at the end of axes) – Srinivas May 01 '20 at 12:39
  • 1
    Your values have an offset of 1E8, but it isn't log scale. Maybe this question might help? https://stackoverflow.com/questions/11855363/how-to-remove-relative-shift-in-matplotlib-axis – DavidG May 01 '20 at 12:55
  • ax.get_yaxis().get_major_formatter().set_scientific(False) without the for loop, solved the problem for the first graph, but not for the second – Srinivas May 04 '20 at 12:37

0 Answers0