2017-05-03 49 views
2

我正在使用seaborn模塊生成類似於以下示例的繪圖。詞彙散佈圖是seaborn

import pandas as pd 
import matplotlib.pyplot as plt 
import numpy as np 
import seaborn as sns 
location = "/global/scratch/umalmonj/WRF/juris/golden_hourly_manual_obs.csv" 

df = pd.read_csv(location,usecols= ["Year","Month","Day","Time","Weather"],parse_dates=[["Year","Month","Day","Time"]]) 

我有一個DF,看起來像:

 Year_Month_Day_Time  Weather 
0 2010-01-01 00:00:00   NaN 
1 2010-01-01 01:00:00   NaN 
2 2010-01-01 02:00:00   NaN 
..  
7 2010-01-01 07:00:00   Snow 
8 2010-01-01 08:00:00   Snow 
9 2010-01-01 09:00:00 Snow Showers 
.. 
18 2010-01-01 18:00:00   NaN 
19 2010-01-01 19:00:00   NaN 
20 2010-01-01 20:00:00   NaN 
...     ...   ... 
2861 2010-04-30 05:00:00 Mainly Clear 
2862 2010-04-30 06:00:00 Mainly Clear 
2863 2010-04-30 07:00:00 Mostly Cloudy 

我想創建一個不同的天氣類的東西類似下面的情節seaborn stripplot。 lexical dispersion plot

也稱爲詞法分散圖。

任何幫助將是偉大的! CSV格式

我的樣本數據集可以在這裏 https://www.dropbox.com/s/ulzz5x3rsl2yjd5/sample_data.csv?dl=0

+0

這將是好了很多,如果你添加一些代碼來至少產生一個例子集或者將您的數據集作爲csv共享。正如你要求潛在的答覆者在幫助你之前自己做許多工作一樣生成數據。 – mwaskom

+0

謝謝@mwaskom,這是個好主意 – jdiction

回答

2

發現你必須使用stripplot。首先,你必須正確讀取數據的datetime列,然後繪製它:

import pandas as pd 
import matplotlib.pyplot as plt 
import seaborn as sns 

# datetime parser 
dateparse = lambda x: pd.datetime.strptime(x, '%y/%m/%d %H:%M') 
df = pd.read_csv('./sample_data.csv',parse_dates=['DateTime'], date_parser=dateparse) 

# set size of figure 
plt.figure(figsize=(22,6)) 
# use horizontal stripplot with x marker size of 5 
sns.stripplot(y='Weather',x='DateTime', data=df, 
orient='h', marker='X', color='navy', size=5) 
# rotate x tick labels 
plt.xticks(rotation=15) 
# remover borders of plot 
plt.tight_layout() 
plt.show() 

圖是可點擊 Figure is clickable