seaborn 散点图日期时间 xaxis 太宽 [英] seaborn scatterplot datetime xaxis too wide

查看:33
本文介绍了seaborn 散点图日期时间 xaxis 太宽的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个数据框:

pd.DataFrame({'Depth': {0: 0.2,
  1: 0.4,
  2: 0.4,
  3: 0.4,
  4: 0.4,
  5: 0.4,
  6: 0.6000000000000001,
  7: 0.4,
  8: 3.2,
  9: 2.0},
 'DateTimeUTC': {0: Timestamp('2018-03-28 06:25:08'),
  1: Timestamp('2018-03-28 06:25:49'),
  2: Timestamp('2018-03-28 06:27:06'),
  3: Timestamp('2018-03-28 06:32:11'),
  4: Timestamp('2018-03-28 06:32:59'),
  5: Timestamp('2018-03-28 06:34:02'),
  6: Timestamp('2018-03-28 06:35:38'),
  7: Timestamp('2018-03-28 06:37:04'),
  8: Timestamp('2018-03-28 06:39:08'),
  9: Timestamp('2018-03-28 06:40:52')}})

看起来像这样:

<table>
  <tr><th></th><th>Depth</th><th>DateTimeUTC</th></tr>
  <tr><th>0</th><td>0.2</td><td>2018-03-28 06:25:08</td></tr>
  <tr><th>1</th><td>0.4</td><td>2018-03-28 06:25:49</td></tr>
  <tr><th>2</th><td>0.4</td><td>2018-03-28 06:27:06</td></tr>
  <tr><th>3</th><td>0.4</td><td>2018-03-28 06:32:11</td></tr>
  <tr><th>4</th><td>0.4</td><td>2018-03-28 06:32:59</td></tr>
  <tr><th>5</th><td>0.4</td><td>2018-03-28 06:34:02</td></tr>
  <tr><th>6</th><td>0.6</td><td>2018-03-28 06:35:38</td></tr>
  <tr><th>7</th><td>0.4</td><td>2018-03-28 06:37:04</td></tr>
  <tr><th>8</th><td>3.2</td><td>2018-03-28 06:39:08</td></tr>
  <tr><th>9</th><td>2.0</td><td>2018-03-28 06:40:52</td></tr>
</table>

注意所有 DateTimeUTC 都在 2018 年之内.当我尝试使用 sns.scatterplot 绘制深度与时间的关系图时,我得到:

Note the all DateTimeUTC are within 2018. When I try to plot depth vs time using sns.scatterplot I get:

sns.scatterplot('DateTimeUTC', 'Depth', data=df)

为什么 X 轴从 2000 年开始?我做错了什么吗?

Why does the X-axis start at year 2000? Am I doing something wrong?

推荐答案

我在 Github 上将问题作为 issue 发布,并得到了这个 很好的回应.基本上,问题在于 plt.scatter 不能很好地处理日期,而 seaborn 使用它.如果 seaborn 会为 x 轴添加类型检查,而是使用 plt.plot_date 作为日期值,这将被修复.同时,您可以创建一个自定义版本的 sns.scatterplot 来做到这一点.

I posted the question as an issue on Github, and got this great response. Basically, the problem is that plt.scatter does not deal with dates well, and seaborn uses it. If seaborn will add a type check for the x-axis, which uses plt.plot_date for date values instead, this will be fixed. In the meanwhile, one can create a custom version of sns.scatterplot that does excatly that.

这篇关于seaborn 散点图日期时间 xaxis 太宽的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆