Python中的数据可用性图表 [英] Data Availability Chart in Python

查看:130
本文介绍了Python中的数据可用性图表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道Python是否可以绘制带有多个变量的时间序列的数据可用性.下面显示了一个示例,该示例摘自 Visavail.js-时间数据可用性图表.

I am wondering if Python has something to plot the data availability of time series with multiple variables. An example is shown below taken from Visavail.js - A Time Data Availability Chart.

推荐答案

以下是在Jupyter笔记本中使用plotly的建议:

Here's a suggestion using plotly in a Jupyter Notebook:

代码:

import random
import pandas as pd
import plotly.express as px
from random import choices

# random data with a somewhat higher
# probability of 1 than 0 to mimic OPs data
random.seed(1)
vals=[0,1]
prob=[0.4, 0.6]
choices(vals, prob)

data=[]
for i in range(0,5):
    data.append([choices(vals, prob)[0] for c in range(0,10)])

# organize data in a pandas dataframe
df=pd.DataFrame(data).T
df.columns=['Balance Sheet', 'Closing Price', 'Weekly Report', 'Analyst Data', 'Annual Report']
drng=pd.date_range(pd.datetime(2080, 1, 1).strftime('%Y-%m-%d'), periods=df.shape[0]).tolist()
df['date']=[d.strftime('%Y-%m-%d') for d in drng]
dfm=pd.melt(df, id_vars=['date'], value_vars=df.columns[:-1])

# plotly express
fig = px.bar(dfm, x="date", y="variable", color='value', orientation='h',
             hover_data=["date"],
             height=600,
             color_continuous_scale=['firebrick', '#2ca02c'],
             title='Data Availabiltiy Plot',
             template='plotly_white',
            )

fig.update_layout(yaxis=dict(title=''), xaxis=dict(title='', showgrid=False, gridcolor='grey',
                  tickvals=[],
                            )
                 )
fig.show()

这篇关于Python中的数据可用性图表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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