0

I want the scatterplot to get the units in millions (e.g. 10e6) instead of to the default unit for this data set (i.e. 10e9). Ideally, both axis would look identical with same axis units and same ticks. I have tried the solution here to no avail. Am I missing something?

Example code:

mtcars = pd.read_csv('https://gist.githubusercontent.com/seankross/a412dfbd88b3db70b74b/raw/5f23f993cd87c283ce766e7ac6b329ee7cc2e1d1/mtcars.csv')
display(mtcars.head())
mtcars['qsec'] = mtcars['qsec']*100000000
mtcars['wt'] = mtcars['wt'] *100000000
display(mtcars.head())

plt.scatter(x=mtcars['qsec'],y=mtcars['wt'])
plt.show()

Plot with scale 10e9 and different ticks

user3507584
  • 3,246
  • 5
  • 42
  • 66
  • 1
    i usually use this `OOMFormatter`: [Set scientific notation with fixed exponent and significant digits](https://stackoverflow.com/a/42658124/13138364) – tdy Nov 05 '21 at 15:36
  • 1
    in your case, something like `plt.gca().yaxis.set_major_formatter(OOMFormatter(6, '%1.1f'))` – tdy Nov 05 '21 at 15:37
  • 2
    `plt.ticklabel_format(style='sci', scilimits=(6, 6))`? – Emma Nov 05 '21 at 15:39
  • 1
    that also works, but i think you just lose control of the decimal formatting – tdy Nov 05 '21 at 15:44
  • Thanks for the comments. I will use @Emma solution as it is neater. – user3507584 Nov 05 '21 at 15:46

0 Answers0