'matplotlib plot saved empty
My plot is saved to png without any dots.
This is my code, with the boring stuff cut out:
import sys
import matplotlib.pyplot as plt
plt.style.use('seaborn-whitegrid')
import numpy as np
region_sales = {
'region1': {'price': 100, 'volume': 20},
'region2': {'price': 200, 'volume': 80},
'region3': {'price': 120, 'volume': 600},
'region4': {'price': 300, 'volume': 92},
'region5': {'price': 57, 'volume': 10},
'region6': {'price': 900, 'volume': 128}
}
for region, data in region_sales.items():
region_name = region
volume = data['volume']
price = data['price']
plt.scatter(price, volume, marker='o',
label=region_name)
print('{}\t{}\t{}'.format(region_name, volume, price))
plt.legend(numpoints=1)
plt.xlim(0, 1.8)
plt.savefig('test.png')
The output of this code is:
region1 25.666666666666668 800100.0
region2 7374.638676844784 1000000.0
region3 85.78061224489795 850500.0
region4 148.5267175572519 1200000.0
region5 77.74809160305344 1444000.0
region6 634.1374045801526 994900.0
And an image is saved to test.png, with X and Y axis that match the data, and with a legend that matches the region names. But there are no points on the plot. Just axis, a grid and a legend.
What Am I missing?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
