2013-08-19 29 views
3

我是新來matplotlib,我想創建一個情節,包含以下信息:繪製位數,中位數和推廣使用SciPy的和matplotlib

  1. 一個連線大約200可變長度向量的中位數(輸入)
  2. 連接這些向量的相應分位數的線。
  3. 加入相應點差線(最大點和最小點)的一條線。

所以基本上,它有點像一個連續的盒子情節。

謝謝!

+1

爲了清楚起見,你的問題被擱置了,因爲它的內容如下:'請爲我做我的工作'或'請爲我做一些免費的開發工作'。如果您顯示您嘗試過_anything_,您會在這裏得到更好的迴應。人們很樂意幫助您_fix_您的代碼,但不太可能爲您編寫代碼。 – tacaswell

+0

這個問題在標記庫的術語中很好地形成,這意味着@ user2696275表明對正在解決的問題有最小的理解。 –

+0

但我完全同意@tcaswell。 –

回答

8

只需使用scipymatplotlib(您標記只在你的問題這些庫)是一個有點冗長,但這裏是你會怎麼做(我做它僅適用於位數):

import numpy as np 
from scipy.stats import mstats 
import matplotlib.pyplot as plt 

# Create 10 columns with 100 rows of random data 
rd = np.random.randn(100, 10) 
# Calculate the quantiles column wise 
quantiles = mstats.mquantiles(rd, axis=0) 
# Plot it 
labels = ['25%', '50%', '75%'] 
for i, q in enumerate(quantiles): 
    plt.plot(q, label=labels[i]) 
plt.legend() 

它給你:

enter image description here

現在,我會試圖說服你去嘗試大熊貓庫:)

import numpy as np 
import pandas as pd 
# Create random data 
rd = pd.DataFrame(np.random.randn(100, 10)) 
# Calculate all the desired values 
df = pd.DataFrame({'mean': rd.mean(), 'median': rd.median(), 
        '25%': rd.quantile(0.25), '50%': rd.quantile(0.5), 
        '75%': rd.quantile(0.75)}) 
# And plot it 
df.plot() 

您將獲得:

enter image description here

或者你可以得到所有的統計數據,在短短一行:

rd.describe().T.drop('count', axis=1).plot() 

enter image description here

注:我放棄了count自它不是「5號碼摘要」的一部分。

+0

我會做類似的事情,我喜歡你指出大熊貓有多麼偉大,但是你應該花一點時間談談爲什麼你只需要輸入numpy和熊貓,而不是「scipy和matplotlib」。 –

+0

我真的很喜歡熊貓,我想引誘更多的人使用它:)但是你說得對,我只加了'scipy'和'matplotlib'的例子。 –

+0

哦,我顯然不清楚,對不起:-) - 我喜歡你的選擇,也真的支持它。現在沒問題,但我只是想讓你花點時間說服提問者,並告訴他你選擇了熊貓/ numpy。 –