词汇分散情节是天生的 [英] Lexical dispersion plot is seaborn
本文介绍了词汇分散情节是天生的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用seaborn模块生成类似于以下示例的图。
将熊猫导入为pd
导入matplotlib.pyplot as plt
导入numpy as np
导入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天气
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雪
9 2010-01-01 09:00:00阵雪
..
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主要清除
2862 2010-04-30 06:00:00主要清除
2863 2010-04-30 07:00:00大部分多云
我想用不同的天气类别创建类似的海上带状图到以下情节。
也称为词汇分散图。
任何
我的csv格式的示例数据集可在此处找到
I am using the seaborn module to produce a plot similar to the example below.
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"]])
I have a df that looks like:
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
I want to create a seaborn stripplot with the different weather categories something similar to the following plot.
Also known as a lexical dispersion plot.
Any help would be great!
My sample dataset in a csv format can be found here https://www.dropbox.com/s/ulzz5x3rsl2yjd5/sample_data.csv?dl=0
解决方案
You have to use stripplot
. Firstly, you have to properly read datetime column of your data and then plot it:
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
这篇关于词汇分散情节是天生的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文