一个小时后:
__author__ = 'madevelasco'
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
def group(x, max, min, iters):
total_range = max - min
for i in range(0, iters):
if (x > min + i*total_range/iters and x <= min + (i+1)*total_range/iters):
return i
def newPlots():
df = pd.DataFrame(np.random.randn(100, 2), columns=['x', 'y'])
df.plot(x = 'x', y = 'y', kind = 'scatter', alpha=0.5)
plt.show()
##Sort by the column you want
df.sort_values(['x'], ascending=[False], inplace=True)
result = df.reset_index(drop=True).copy()
#Number of groups you want
iterations = 3
max_range = df['x'].max()
min_range = df['x'].min()
total_range = max_range - min_range
result['group'] = result.apply(lambda x: group(x['x'], max_range, min_range, iterations ), axis=1)
print(result)
for x in range (0, iterations):
lower = min_range + (x)*total_range/iterations
upper = min_range + (1+x)*total_range/iterations
new = result[result['group'] == x]
new.plot(x = 'x', y = 'y', kind = 'scatter', alpha=0.3)
axes = plt.gca()
axes.set_xlim([lower, upper])
axes.set_ylim([df['y'].min(),df['y'].max()])
plt.show()
if __name__ == '__main__':
newPlots()
我用熊猫来做到这一点。老实说,可视化的想法是将所有数据放在一个图表中,但不会像那样分开。为了保持日期的概念,甚至为了可读性,应该固定其中一个轴。我在两次编辑之间做了
所有点的图像
子地块