やりたいこと
縦軸に時間、横軸に日付を取ったときの範囲棒グラフ及びそれらの棒グラフを1つにしたものが表す面積を描画したいです。
現状の問題点
範囲がうまくコードに落とせておらず、実行結果が0:00からの棒グラフとなってしまいます。
作成したコード
import pandas as pd import numpy as np import datetime as dt from IPython.core.display import display import matplotlib import matplotlib.pyplot as plt plt.style.use('ggplot') font = {'family' : 'meiryo'} matplotlib.rc('font', **font) from matplotlib import dates as mdates from datetime import datetime as dt from pylab import rcParams rcParams['figure.figsize'] = 20,20 www = ['2019-05-07', '2019-05-08', '2019-05-09', '2019-05-10', '2019-05-13', '2019-05-14', '2019-05-15', '2019-05-16', '2019-05-17', '2019-05-20', '2019-05-21', '2019-05-22', '2019-05-23', '2019-05-24', '2019-05-27', '2019-05-28', '2019-05-29', '2019-05-30', '2019-05-31'] xxx = ['09:00', '09:00', '09:00', '09:00', '09:00', '09:00', '09:00', '09:00', '09:00', '09:00', '09:00', '09:00', '10:10', '09:00', '09:00', '09:00', '09:56', '13:01', '09:00'] yyy = ['18:55', '19:04', '18:29', '18:32', '20:26', '18:05', '22:28', '18:02', '19:39', '20:53', '18:18', '18:03', '20:05', '18:20', '18:10', '18:31', '19:20', '19:10', '18:30'] www = [dt.strptime(d, '%Y-%m-%d') for d in www] xxx = [dt.strptime(d, '%H:%M') for d in xxx] yyy = [dt.strptime(d, '%H:%M') for d in yyy] # プロット ax = plt.subplot() ax.bar(www,xxx) ax.bar(www,yyy) # X軸 ax.xaxis.set_major_locator(mdates.DayLocator()) ax.xaxis.set_major_formatter(mdates.DateFormatter("%m/%d")) ax.set_xlim([dt.strptime('2019-5-1','%Y-%m-%d'), dt.strptime('2019-6-1', '%Y-%m-%d')]) # Y軸 ax.yaxis.set_major_locator(mdates.HourLocator()) ax.yaxis.set_major_formatter(mdates.DateFormatter("%H:%M")) ax.set_ylim([dt.strptime('22:59','%H:%M'), dt.strptime('07:00','%H:%M')]) plt.xticks(rotation=50) plt.show()
どのようにすれば範囲棒グラフにできるか、また、それらを一つの面積にしたエリアチャートのようなものが描けるかご教示頂けましたら幸いです。
何卒よろしくお願い申し上げます。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/07/22 04:16