1

Sorry for my bad English.

I have a list :

found_time = ['2019-02-28 00:24:16', '2019-02-28 00:22:30', '2019-02-27 08:08:21', ... ... , '2019-02-01 22:21:10', '2019-02-01 00:21:10']

expected plot

and I am trying to make plot table like ↑this one. and Chris A gave me a code which plots like ↓this.

    import pandas as pd
    import numpy as np

    s = pd.Series(np.ones(len(found_time)), index=pd.DatetimeIndex(found_time))
    s = s.resample('H').sum()

    plt.scatter(s.index.hour, s.index.date, s=s, color='k')

    # yticks
    yticks = pd.date_range('2019-02-01', '2019-02-28', freq='D')
    plt.yticks(yticks, [y.strftime('%m-%d') for y in yticks])
    plt.ylim('2019-02-01', '2019-02-28')

    # xticks
    xticks = np.arange(24)
    plt.xticks(xticks, ['{0:02d}:00'.format(x) for x in xticks], rotation=45,ha='right')

result plot

and the problem is it only plots on exact time. ex)08:45:33 -> 08:00, 07:12:09 -> 07:00

Question: How do you plot more precisely? Not hourly.

1 Answer 1

1
s = pd.Series(np.ones(len(found_time)), index=pd.DatetimeIndex(found_time))

plt.scatter(s.index.time, s.index.date, color='k')

# yticks
yticks = pd.date_range('2019-02-01', '2019-02-28', freq='D')
plt.yticks(yticks, [y.strftime('%m-%d') for y in yticks])
plt.ylim('2019-02-01', '2019-02-28')


# xticks
xticks = pd.date_range('00:00', '23:00', freq='H').time
plt.xticks(xticks, [x.strftime('%H:%M') for x in xticks], rotation=45,ha='right')

pay attention: plt.scatter(s.index.time, s.index.date, color='k')

and xticks can compare with s.index.time

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.