小時後嘛:
__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()
我用熊貓來了這一點。老實說,可視化的想法是將所有數據都放在一個圖中,但不能像這樣分開。爲了保持你的日期的想法,甚至爲了可讀性,其中一個軸應該是固定的。我的編輯之間沒有
所有點的圖像
子地塊
將軸('縮放')做這項工作嗎?它應該如何實施? – durbachit
http://stackoverflow.com/a/30266598/3826323有幫助嗎? – Daniele