绘制所有NaN的DataFrame

时间:2019-02-03 18:05:09

标签: python-3.x pandas matplotlib

我有一个正在开发的应用程序,其中返回带有DatetimeIndex的np.nan的Pandas数据帧是有效的结果。没有用于查询的数据,我需要该图以形成带有DatetimeIndex且没有数据点的轴。这打破了matplotlib关于边界框的想法,该边界框通过将数据转换为浮点数来获得限制。

我认为应该有一个不难看的解决方法,例如设置bbox限制的调用,但到目前为止我还没有弄清楚。

目前,我正在将数据框与另一个具有零的数据框连接起来,然后循环遍历各列以将虚拟列的线型设置为“无”。

# dummy must also be moved to the end of the dataframe to not
# not break the legend in my app.
ax.plot(df)
dummy_line = ax.get_lines()[-1].set_linestyle('None')

这确实是一个丑陋的hack,它使代码更加复杂,并迫使特殊功能对其进行抽象。

Matplotlib的内置功能是否可以更轻松地解决更多问题?

示例

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

index = pd.date_range('2019-01-01T12:00:00', '2019-01-2T12:00:00', freq='3T')
data = [np.nan for i in index]
df = pd.DataFrame({'test':data}, index=index)
fig, ax = plt.subplots(nrows=1)
ax.plot(df)
plt.show()
# Ultimately I want to use date Locators which offer a different
# error b/c there's too many ticks.

版本信息

  • matplotlib 2.0.2 np113py36_0
  • Python 3.x

0 个答案:

没有答案
相关问题