newbieprogrammer095
newbieprogrammer095

Reputation: 73

matplotlib plt.scatter showing wrong x axis data

I have a json

[
  {
    "price": 649000,
    "bedrooms": 3,
    "bathrooms": 2.0,
    "yr_built": 1984,
    "sqft_lot": 3250.0,
    "zpid": 15767255,
    "address": "7036 Overlook Dr"
  },
  {
    "price": 649000,
    "bedrooms": 3,
    "bathrooms": 2.0,
    "yr_built": 1984,
    "sqft_lot": 3250.0,
    "zpid": 15767255,
    "address": "7036 Overlook Dr"
  },
]

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


data = pd.read_json(json.dumps(json_data))
plt.scatter(data.price, data.sqft_lot)

Why is it that for x-axis data.price the number ranges are only showing from 1-4 and not the actual price themselves?

enter image description here

Upvotes: 1

Views: 279

Answers (1)

Zephyr
Zephyr

Reputation: 12496

The x axis actually shows the correct price values, but the axis is set to scientific notation. You can turn this notation on or off with matplotlib.pyplot.ticklabel_format:

OFF

plt.ticklabel_format(axis = 'x', style = 'plain')

enter image description here

ON

plt.ticklabel_format(axis = 'x', style = 'scientific', scilimits = (0, 0))

enter image description here

Upvotes: 1

Related Questions