показывает только каждые <n>даты на оси х (или группирование по месяцам), чтобы уменьшить беспорядок на оси х - PullRequest
2 голосов
/ 09 апреля 2019

В настоящее время я изучаю немного Python, используя Jupyter Notebook и библиотеку matplotlib для создания некоторых графиков из данных JSON.Я был в состоянии создать диаграммы, и это здорово, но я не уверен, как снять помехи с моей оси X.Смотрите скриншот ниже.Для каждого дня есть значение, и данные передаются в течение сотен дней. Это создает очень загроможденную ось X, которую невозможно прочитать.

Код:

dates = [i['daily_sales_date'] for i in json_data]
values = [i['daily_sales'] for i in json_data]
print('sample date: ' + dates[0])
print('sample value: ' + str(values[0]))
df = pd.DataFrame({'dates':dates, 'values':values})
df['dates']  = [pd.to_datetime(i) for i in df['dates']]
plt.bar(dates, values)

Результат:

enter image description here

Эта толстая черная полоса - все мои даты:).Я попытался просмотреть некоторые примеры, которые предположительно не загромождают даты оси X, но я не заставил их работать.Я был бы рад показать только подмножество дат вдоль оси, или даже просто показать названия месяцев.Лучшее, что я могу сделать, это заставить ярлыки оси X вообще не появляться: / Какой совет?

enter image description here

Я попытался сделать следующее в соответствии с одним из предложений:

from matplotlib.dates import MonthLocator
register_matplotlib_converters()

Затем создать график:

enter image description here

Как видите, у меня сейчас 2019 (год), но месяцев нет?Пример данных, приведенных ниже для ясности (по запросу)

[
    {
        "RowInsertDateTime": "2019-04-10T13:10:00.6",
        "ServerName": "P781S001",
        "StoreName": "PRICELINE WERRIBEE",
        "daily_sales": 4994.2,
        "daily_sales_date": "2019-04-10T00:00:00"
    },
    {
        "RowInsertDateTime": "2019-04-09T23:00:01.213",
        "ServerName": "P781S001",
        "StoreName": "PRICELINE WERRIBEE",
        "daily_sales": 8868.75,
        "daily_sales_date": "2019-04-09T00:00:00"
    },
    {
        "RowInsertDateTime": "2019-04-08T23:00:02.093",
        "ServerName": "P781S001",
        "StoreName": "PRICELINE WERRIBEE",
        "daily_sales": 4618.55,
        "daily_sales_date": "2019-04-08T00:00:00"
    },
    {
        "RowInsertDateTime": "2019-04-07T23:00:01.52",
        "ServerName": "P781S001",
        "StoreName": "PRICELINE WERRIBEE",
        "daily_sales": 5710.01,
        "daily_sales_date": "2019-04-07T00:00:00"
    },
    {
        "RowInsertDateTime": "2019-04-06T23:00:01.42",
        "ServerName": "P781S001",
        "StoreName": "PRICELINE WERRIBEE",
        "daily_sales": 9674.46,
        "daily_sales_date": "2019-04-06T00:00:00"
    },
    {
        "RowInsertDateTime": "2019-04-05T23:50:01.977",
        "ServerName": "P781S001",
        "StoreName": "PRICELINE WERRIBEE",
        "daily_sales": 9243.66,
        "daily_sales_date": "2019-04-05T00:00:00"
    },
    {
        "RowInsertDateTime": "2019-04-04T23:50:01.5",
        "ServerName": "P781S001",
        "StoreName": "PRICELINE WERRIBEE",
        "daily_sales": 8865.75,
        "daily_sales_date": "2019-04-04T00:00:00"
    },
    {
        "RowInsertDateTime": "2019-04-03T23:00:01.003",
        "ServerName": "P781S001",
        "StoreName": "PRICELINE WERRIBEE",
        "daily_sales": 5530.14,
        "daily_sales_date": "2019-04-03T00:00:00"
    },
    {
        "RowInsertDateTime": "2019-04-02T23:00:01.71",
        "ServerName": "P781S001",
        "StoreName": "PRICELINE WERRIBEE",
        "daily_sales": 4893.77,
        "daily_sales_date": "2019-04-02T00:00:00"
    },
    {
        "RowInsertDateTime": "2019-04-01T23:00:01.61",
        "ServerName": "P781S001",
        "StoreName": "PRICELINE WERRIBEE",
        "daily_sales": 3741.6,
        "daily_sales_date": "2019-04-01T00:00:00"
    },
    {
        "RowInsertDateTime": "2019-03-31T23:00:00.893",
        "ServerName": "P781S001",
        "StoreName": "PRICELINE WERRIBEE",
        "daily_sales": 8727.52,
        "daily_sales_date": "2019-03-31T00:00:00"
    },
    {
        "RowInsertDateTime": "2019-03-30T23:00:01.263",
        "ServerName": "P781S001",
        "StoreName": "PRICELINE WERRIBEE",
        "daily_sales": 9572.48,
        "daily_sales_date": "2019-03-30T00:00:00"
    },
    {
        "RowInsertDateTime": "2019-03-29T23:50:01.937",
        "ServerName": "P781S001",
        "StoreName": "PRICELINE WERRIBEE",
        "daily_sales": 20003.71,
        "daily_sales_date": "2019-03-29T00:00:00"
    },
    {
        "RowInsertDateTime": "2019-03-28T23:50:00.933",
        "ServerName": "P781S001",
        "StoreName": "PRICELINE WERRIBEE",
        "daily_sales": 29890.54,
        "daily_sales_date": "2019-03-28T00:00:00"
    },
    {
        "RowInsertDateTime": "2019-03-27T23:00:01.267",
        "ServerName": "P781S001",
        "StoreName": "PRICELINE WERRIBEE",
        "daily_sales": 19669.24,
        "daily_sales_date": "2019-03-27T00:00:00"
    },
    {
        "RowInsertDateTime": "2019-03-26T23:00:13.68",
        "ServerName": "P781S001",
        "StoreName": "PRICELINE WERRIBEE",
        "daily_sales": 18655.44,
        "daily_sales_date": "2019-03-26T00:00:00"
    },
    {
        "RowInsertDateTime": "2019-03-25T23:00:12.427",
        "ServerName": "P781S001",
        "StoreName": "PRICELINE WERRIBEE",
        "daily_sales": 4876.38,
        "daily_sales_date": "2019-03-25T00:00:00"
    },
    {
        "RowInsertDateTime": "2019-03-24T23:00:16.313",
        "ServerName": "P781S001",
        "StoreName": "PRICELINE WERRIBEE",
        "daily_sales": 8467.17,
        "daily_sales_date": "2019-03-24T00:00:00"
    },
    {
        "RowInsertDateTime": "2019-03-23T23:00:23.517",
        "ServerName": "P781S001",
        "StoreName": "PRICELINE WERRIBEE",
        "daily_sales": 12542.34,
        "daily_sales_date": "2019-03-23T00:00:00"
    },
    {
        "RowInsertDateTime": "2019-03-22T23:50:14.363",
        "ServerName": "P781S001",
        "StoreName": "PRICELINE WERRIBEE",
        "daily_sales": 12119.07,
        "daily_sales_date": "2019-03-22T00:00:00"
    },
    {
        "RowInsertDateTime": "2019-03-21T23:50:12.527",
        "ServerName": "P781S001",
        "StoreName": "PRICELINE WERRIBEE",
        "daily_sales": 9403.31,
        "daily_sales_date": "2019-03-21T00:00:00"
    },
    {
        "RowInsertDateTime": "2019-03-20T23:00:15.797",
        "ServerName": "P781S001",
        "StoreName": "PRICELINE WERRIBEE",
        "daily_sales": 5872.87,
        "daily_sales_date": "2019-03-20T00:00:00"
    },
    {
        "RowInsertDateTime": "2019-03-19T23:10:09.547",
        "ServerName": "P781S001",
        "StoreName": "PRICELINE WERRIBEE",
        "daily_sales": 4634.91,
        "daily_sales_date": "2019-03-19T00:00:00"
    },
    {
        "RowInsertDateTime": "2019-03-18T23:00:10.887",
        "ServerName": "P781S001",
        "StoreName": "PRICELINE WERRIBEE",
        "daily_sales": 5789.16,
        "daily_sales_date": "2019-03-18T00:00:00"
    },
    {
        "RowInsertDateTime": "2019-03-17T23:00:07.93",
        "ServerName": "P781S001",
        "StoreName": "PRICELINE WERRIBEE",
        "daily_sales": 9743.17,
        "daily_sales_date": "2019-03-17T00:00:00"
    },
    {
        "RowInsertDateTime": "2019-03-16T23:00:12.367",
        "ServerName": "P781S001",
        "StoreName": "PRICELINE WERRIBEE",
        "daily_sales": 10729.08,
        "daily_sales_date": "2019-03-16T00:00:00"
    },
    {
        "RowInsertDateTime": "2019-03-15T23:50:09.177",
        "ServerName": "P781S001",
        "StoreName": "PRICELINE WERRIBEE",
        "daily_sales": 9404.83,
        "daily_sales_date": "2019-03-15T00:00:00"
    },
    {
        "RowInsertDateTime": "2019-03-14T23:50:11.423",
        "ServerName": "P781S001",
        "StoreName": "PRICELINE WERRIBEE",
        "daily_sales": 9029.93,
        "daily_sales_date": "2019-03-14T00:00:00"
    },
    {
        "RowInsertDateTime": "2019-03-13T23:00:17.653",
        "ServerName": "P781S001",
        "StoreName": "PRICELINE WERRIBEE",
        "daily_sales": 4464.14,
        "daily_sales_date": "2019-03-13T00:00:00"
    },
    {
        "RowInsertDateTime": "2019-03-12T23:00:14.063",
        "ServerName": "P781S001",
        "StoreName": "PRICELINE WERRIBEE",
        "daily_sales": 4711.15,
        "daily_sales_date": "2019-03-12T00:00:00"
    },
    {
        "RowInsertDateTime": "2019-03-11T23:00:11.227",
        "ServerName": "P781S001",
        "StoreName": "PRICELINE WERRIBEE",
        "daily_sales": 7090.3,
        "daily_sales_date": "2019-03-11T00:00:00"
    },
    {
        "RowInsertDateTime": "2019-03-10T23:00:07.127",
        "ServerName": "P781S001",
        "StoreName": "PRICELINE WERRIBEE",
        "daily_sales": 8083.23,
        "daily_sales_date": "2019-03-10T00:00:00"
    },
    {
        "RowInsertDateTime": "2019-03-09T23:10:10.253",
        "ServerName": "P781S001",
        "StoreName": "PRICELINE WERRIBEE",
        "daily_sales": 10253.7,
        "daily_sales_date": "2019-03-09T00:00:00"
    },
    {
        "RowInsertDateTime": "2019-03-08T23:50:09.863",
        "ServerName": "P781S001",
        "StoreName": "PRICELINE WERRIBEE",
        "daily_sales": 12339.06,
        "daily_sales_date": "2019-03-08T00:00:00"
    },
    {
        "RowInsertDateTime": "2019-03-07T23:50:10.497",
        "ServerName": "P781S001",
        "StoreName": "PRICELINE WERRIBEE",
        "daily_sales": 10200.52,
        "daily_sales_date": "2019-03-07T00:00:00"
    },
    {
        "RowInsertDateTime": "2019-03-06T23:10:10.87",
        "ServerName": "P781S001",
        "StoreName": "PRICELINE WERRIBEE",
        "daily_sales": 6694.55,
        "daily_sales_date": "2019-03-06T00:00:00"
    },
    {
        "RowInsertDateTime": "2019-03-05T23:10:08.707",
        "ServerName": "P781S001",
        "StoreName": "PRICELINE WERRIBEE",
        "daily_sales": 5779.48,
        "daily_sales_date": "2019-03-05T00:00:00"
    },
    {
        "RowInsertDateTime": "2019-03-04T23:00:09.39",
        "ServerName": "P781S001",
        "StoreName": "PRICELINE WERRIBEE",
        "daily_sales": 4954.72,
        "daily_sales_date": "2019-03-04T00:00:00"
    },
    {
        "RowInsertDateTime": "2019-03-03T23:00:10.75",
        "ServerName": "P781S001",
        "StoreName": "PRICELINE WERRIBEE",
        "daily_sales": 8473.28,
        "daily_sales_date": "2019-03-03T00:00:00"
    },
    {
        "RowInsertDateTime": "2019-03-02T23:00:09.637",
        "ServerName": "P781S001",
        "StoreName": "PRICELINE WERRIBEE",
        "daily_sales": 11327.68,
        "daily_sales_date": "2019-03-02T00:00:00"
    },
    {
        "RowInsertDateTime": "2019-03-01T23:50:11.49",
        "ServerName": "P781S001",
        "StoreName": "PRICELINE WERRIBEE",
        "daily_sales": 11075.8,
        "daily_sales_date": "2019-03-01T00:00:00"
    },
    {
        "RowInsertDateTime": "2019-02-28T23:50:10.217",
        "ServerName": "P781S001",
        "StoreName": "PRICELINE WERRIBEE",
        "daily_sales": 9143.1,
        "daily_sales_date": "2019-02-28T00:00:00"
    },
    {
        "RowInsertDateTime": "2019-02-27T23:00:09.44",
        "ServerName": "P781S001",
        "StoreName": "PRICELINE WERRIBEE",
        "daily_sales": 5523.66,
        "daily_sales_date": "2019-02-27T00:00:00"
    },
    {
        "RowInsertDateTime": "2019-02-26T23:00:08.913",
        "ServerName": "P781S001",
        "StoreName": "PRICELINE WERRIBEE",
        "daily_sales": 5235.5,
        "daily_sales_date": "2019-02-26T00:00:00"
    },
    {
        "RowInsertDateTime": "2019-02-25T23:00:19.74",
        "ServerName": "P781S001",
        "StoreName": "PRICELINE WERRIBEE",
        "daily_sales": 5379.84,
        "daily_sales_date": "2019-02-25T00:00:00"
    },
    {
        "RowInsertDateTime": "2019-02-24T23:00:09.44",
        "ServerName": "P781S001",
        "StoreName": "PRICELINE WERRIBEE",
        "daily_sales": 7194.78,
        "daily_sales_date": "2019-02-24T00:00:00"
    },
    {
        "RowInsertDateTime": "2019-02-23T23:00:11.783",
        "ServerName": "P781S001",
        "StoreName": "PRICELINE WERRIBEE",
        "daily_sales": 9438.9,
        "daily_sales_date": "2019-02-23T00:00:00"
    },
    {
        "RowInsertDateTime": "2019-02-22T23:50:07.167",
        "ServerName": "P781S001",
        "StoreName": "PRICELINE WERRIBEE",
        "daily_sales": 9989.46,
        "daily_sales_date": "2019-02-22T00:00:00"
    },
    {
        "RowInsertDateTime": "2019-02-21T23:50:06.98",
        "ServerName": "P781S001",
        "StoreName": "PRICELINE WERRIBEE",
        "daily_sales": 10120.73,
        "daily_sales_date": "2019-02-21T00:00:00"
    },
    {
        "RowInsertDateTime": "2019-02-20T23:00:14.46",
        "ServerName": "P781S001",
        "StoreName": "PRICELINE WERRIBEE",
        "daily_sales": 5732.03,
        "daily_sales_date": "2019-02-20T00:00:00"
    }
]

Ответы [ 3 ]

2 голосов
/ 09 апреля 2019

Ваша главная и единственная проблема в том, что "даты" - это строки.Если вы конвертируете свои строки в даты, график будет выглядеть как положено.Вы делаете это уже внутри фрейма данных, но затем не используете этот столбец ни в одном из следующих кодов.

df = pd.DataFrame({'dates':dates, 'values':values})
df['dates']  = pd.to_datetime(df['dates'])  # possibly format="..."
plt.bar(df['dates'].values, df['values'].values)

# The complete example would be:

import pandas as pd
import matplotlib.pyplot as plt

json_data = [
    {
        "RowInsertDateTime": "2019-04-10T13:10:00.6",
        "ServerName": "P781S001",
        "StoreName": "PRICELINE WERRIBEE",
        "daily_sales": 4994.2,
        "daily_sales_date": "2019-04-10T00:00:00"
    },
    {
        "RowInsertDateTime": "2019-04-09T23:00:01.213",
        "ServerName": "P781S001",
        "StoreName": "PRICELINE WERRIBEE",
        "daily_sales": 8868.75,
        "daily_sales_date": "2019-04-09T00:00:00"
    },
    {
        "RowInsertDateTime": "2019-04-08T23:00:02.093",
        "ServerName": "P781S001",
        "StoreName": "PRICELINE WERRIBEE",
        "daily_sales": 4618.55,
        "daily_sales_date": "2019-04-08T00:00:00"
    },
    {
        "RowInsertDateTime": "2019-04-07T23:00:01.52",
        "ServerName": "P781S001",
        "StoreName": "PRICELINE WERRIBEE",
        "daily_sales": 5710.01,
        "daily_sales_date": "2019-04-07T00:00:00"
    },
    {
        "RowInsertDateTime": "2019-04-06T23:00:01.42",
        "ServerName": "P781S001",
        "StoreName": "PRICELINE WERRIBEE",
        "daily_sales": 9674.46,
        "daily_sales_date": "2019-04-06T00:00:00"
    },
    {
        "RowInsertDateTime": "2019-04-05T23:50:01.977",
        "ServerName": "P781S001",
        "StoreName": "PRICELINE WERRIBEE",
        "daily_sales": 9243.66,
        "daily_sales_date": "2019-04-05T00:00:00"
    },
    {
        "RowInsertDateTime": "2019-04-04T23:50:01.5",
        "ServerName": "P781S001",
        "StoreName": "PRICELINE WERRIBEE",
        "daily_sales": 8865.75,
        "daily_sales_date": "2019-04-04T00:00:00"
    },
    {
        "RowInsertDateTime": "2019-04-03T23:00:01.003",
        "ServerName": "P781S001",
        "StoreName": "PRICELINE WERRIBEE",
        "daily_sales": 5530.14,
        "daily_sales_date": "2019-04-03T00:00:00"
    },
    {
        "RowInsertDateTime": "2019-04-02T23:00:01.71",
        "ServerName": "P781S001",
        "StoreName": "PRICELINE WERRIBEE",
        "daily_sales": 4893.77,
        "daily_sales_date": "2019-04-02T00:00:00"
    },
    {
        "RowInsertDateTime": "2019-04-01T23:00:01.61",
        "ServerName": "P781S001",
        "StoreName": "PRICELINE WERRIBEE",
        "daily_sales": 3741.6,
        "daily_sales_date": "2019-04-01T00:00:00"
    },
    {
        "RowInsertDateTime": "2019-03-31T23:00:00.893",
        "ServerName": "P781S001",
        "StoreName": "PRICELINE WERRIBEE",
        "daily_sales": 8727.52,
        "daily_sales_date": "2019-03-31T00:00:00"
    },
    {
        "RowInsertDateTime": "2019-03-30T23:00:01.263",
        "ServerName": "P781S001",
        "StoreName": "PRICELINE WERRIBEE",
        "daily_sales": 9572.48,
        "daily_sales_date": "2019-03-30T00:00:00"
    },
    {
        "RowInsertDateTime": "2019-03-29T23:50:01.937",
        "ServerName": "P781S001",
        "StoreName": "PRICELINE WERRIBEE",
        "daily_sales": 20003.71,
        "daily_sales_date": "2019-03-29T00:00:00"
    },
    {
        "RowInsertDateTime": "2019-03-28T23:50:00.933",
        "ServerName": "P781S001",
        "StoreName": "PRICELINE WERRIBEE",
        "daily_sales": 29890.54,
        "daily_sales_date": "2019-03-28T00:00:00"
    },
    {
        "RowInsertDateTime": "2019-03-27T23:00:01.267",
        "ServerName": "P781S001",
        "StoreName": "PRICELINE WERRIBEE",
        "daily_sales": 19669.24,
        "daily_sales_date": "2019-03-27T00:00:00"
    },
    {
        "RowInsertDateTime": "2019-03-26T23:00:13.68",
        "ServerName": "P781S001",
        "StoreName": "PRICELINE WERRIBEE",
        "daily_sales": 18655.44,
        "daily_sales_date": "2019-03-26T00:00:00"
    },
    {
        "RowInsertDateTime": "2019-03-25T23:00:12.427",
        "ServerName": "P781S001",
        "StoreName": "PRICELINE WERRIBEE",
        "daily_sales": 4876.38,
        "daily_sales_date": "2019-03-25T00:00:00"
    },
    {
        "RowInsertDateTime": "2019-03-24T23:00:16.313",
        "ServerName": "P781S001",
        "StoreName": "PRICELINE WERRIBEE",
        "daily_sales": 8467.17,
        "daily_sales_date": "2019-03-24T00:00:00"
    },
    {
        "RowInsertDateTime": "2019-03-23T23:00:23.517",
        "ServerName": "P781S001",
        "StoreName": "PRICELINE WERRIBEE",
        "daily_sales": 12542.34,
        "daily_sales_date": "2019-03-23T00:00:00"
    },
    {
        "RowInsertDateTime": "2019-03-22T23:50:14.363",
        "ServerName": "P781S001",
        "StoreName": "PRICELINE WERRIBEE",
        "daily_sales": 12119.07,
        "daily_sales_date": "2019-03-22T00:00:00"
    },
    {
        "RowInsertDateTime": "2019-03-21T23:50:12.527",
        "ServerName": "P781S001",
        "StoreName": "PRICELINE WERRIBEE",
        "daily_sales": 9403.31,
        "daily_sales_date": "2019-03-21T00:00:00"
    },
    {
        "RowInsertDateTime": "2019-03-20T23:00:15.797",
        "ServerName": "P781S001",
        "StoreName": "PRICELINE WERRIBEE",
        "daily_sales": 5872.87,
        "daily_sales_date": "2019-03-20T00:00:00"
    },
    {
        "RowInsertDateTime": "2019-03-19T23:10:09.547",
        "ServerName": "P781S001",
        "StoreName": "PRICELINE WERRIBEE",
        "daily_sales": 4634.91,
        "daily_sales_date": "2019-03-19T00:00:00"
    },
    {
        "RowInsertDateTime": "2019-03-18T23:00:10.887",
        "ServerName": "P781S001",
        "StoreName": "PRICELINE WERRIBEE",
        "daily_sales": 5789.16,
        "daily_sales_date": "2019-03-18T00:00:00"
    },
    {
        "RowInsertDateTime": "2019-03-17T23:00:07.93",
        "ServerName": "P781S001",
        "StoreName": "PRICELINE WERRIBEE",
        "daily_sales": 9743.17,
        "daily_sales_date": "2019-03-17T00:00:00"
    },
    {
        "RowInsertDateTime": "2019-03-16T23:00:12.367",
        "ServerName": "P781S001",
        "StoreName": "PRICELINE WERRIBEE",
        "daily_sales": 10729.08,
        "daily_sales_date": "2019-03-16T00:00:00"
    },
    {
        "RowInsertDateTime": "2019-03-15T23:50:09.177",
        "ServerName": "P781S001",
        "StoreName": "PRICELINE WERRIBEE",
        "daily_sales": 9404.83,
        "daily_sales_date": "2019-03-15T00:00:00"
    },
    {
        "RowInsertDateTime": "2019-03-14T23:50:11.423",
        "ServerName": "P781S001",
        "StoreName": "PRICELINE WERRIBEE",
        "daily_sales": 9029.93,
        "daily_sales_date": "2019-03-14T00:00:00"
    },
    {
        "RowInsertDateTime": "2019-03-13T23:00:17.653",
        "ServerName": "P781S001",
        "StoreName": "PRICELINE WERRIBEE",
        "daily_sales": 4464.14,
        "daily_sales_date": "2019-03-13T00:00:00"
    },
    {
        "RowInsertDateTime": "2019-03-12T23:00:14.063",
        "ServerName": "P781S001",
        "StoreName": "PRICELINE WERRIBEE",
        "daily_sales": 4711.15,
        "daily_sales_date": "2019-03-12T00:00:00"
    },
    {
        "RowInsertDateTime": "2019-03-11T23:00:11.227",
        "ServerName": "P781S001",
        "StoreName": "PRICELINE WERRIBEE",
        "daily_sales": 7090.3,
        "daily_sales_date": "2019-03-11T00:00:00"
    },
    {
        "RowInsertDateTime": "2019-03-10T23:00:07.127",
        "ServerName": "P781S001",
        "StoreName": "PRICELINE WERRIBEE",
        "daily_sales": 8083.23,
        "daily_sales_date": "2019-03-10T00:00:00"
    },
    {
        "RowInsertDateTime": "2019-03-09T23:10:10.253",
        "ServerName": "P781S001",
        "StoreName": "PRICELINE WERRIBEE",
        "daily_sales": 10253.7,
        "daily_sales_date": "2019-03-09T00:00:00"
    },
    {
        "RowInsertDateTime": "2019-03-08T23:50:09.863",
        "ServerName": "P781S001",
        "StoreName": "PRICELINE WERRIBEE",
        "daily_sales": 12339.06,
        "daily_sales_date": "2019-03-08T00:00:00"
    },
    {
        "RowInsertDateTime": "2019-03-07T23:50:10.497",
        "ServerName": "P781S001",
        "StoreName": "PRICELINE WERRIBEE",
        "daily_sales": 10200.52,
        "daily_sales_date": "2019-03-07T00:00:00"
    },
    {
        "RowInsertDateTime": "2019-03-06T23:10:10.87",
        "ServerName": "P781S001",
        "StoreName": "PRICELINE WERRIBEE",
        "daily_sales": 6694.55,
        "daily_sales_date": "2019-03-06T00:00:00"
    },
    {
        "RowInsertDateTime": "2019-03-05T23:10:08.707",
        "ServerName": "P781S001",
        "StoreName": "PRICELINE WERRIBEE",
        "daily_sales": 5779.48,
        "daily_sales_date": "2019-03-05T00:00:00"
    },
    {
        "RowInsertDateTime": "2019-03-04T23:00:09.39",
        "ServerName": "P781S001",
        "StoreName": "PRICELINE WERRIBEE",
        "daily_sales": 4954.72,
        "daily_sales_date": "2019-03-04T00:00:00"
    },
    {
        "RowInsertDateTime": "2019-03-03T23:00:10.75",
        "ServerName": "P781S001",
        "StoreName": "PRICELINE WERRIBEE",
        "daily_sales": 8473.28,
        "daily_sales_date": "2019-03-03T00:00:00"
    },
    {
        "RowInsertDateTime": "2019-03-02T23:00:09.637",
        "ServerName": "P781S001",
        "StoreName": "PRICELINE WERRIBEE",
        "daily_sales": 11327.68,
        "daily_sales_date": "2019-03-02T00:00:00"
    },
    {
        "RowInsertDateTime": "2019-03-01T23:50:11.49",
        "ServerName": "P781S001",
        "StoreName": "PRICELINE WERRIBEE",
        "daily_sales": 11075.8,
        "daily_sales_date": "2019-03-01T00:00:00"
    },
    {
        "RowInsertDateTime": "2019-02-28T23:50:10.217",
        "ServerName": "P781S001",
        "StoreName": "PRICELINE WERRIBEE",
        "daily_sales": 9143.1,
        "daily_sales_date": "2019-02-28T00:00:00"
    },
    {
        "RowInsertDateTime": "2019-02-27T23:00:09.44",
        "ServerName": "P781S001",
        "StoreName": "PRICELINE WERRIBEE",
        "daily_sales": 5523.66,
        "daily_sales_date": "2019-02-27T00:00:00"
    },
    {
        "RowInsertDateTime": "2019-02-26T23:00:08.913",
        "ServerName": "P781S001",
        "StoreName": "PRICELINE WERRIBEE",
        "daily_sales": 5235.5,
        "daily_sales_date": "2019-02-26T00:00:00"
    },
    {
        "RowInsertDateTime": "2019-02-25T23:00:19.74",
        "ServerName": "P781S001",
        "StoreName": "PRICELINE WERRIBEE",
        "daily_sales": 5379.84,
        "daily_sales_date": "2019-02-25T00:00:00"
    },
    {
        "RowInsertDateTime": "2019-02-24T23:00:09.44",
        "ServerName": "P781S001",
        "StoreName": "PRICELINE WERRIBEE",
        "daily_sales": 7194.78,
        "daily_sales_date": "2019-02-24T00:00:00"
    },
    {
        "RowInsertDateTime": "2019-02-23T23:00:11.783",
        "ServerName": "P781S001",
        "StoreName": "PRICELINE WERRIBEE",
        "daily_sales": 9438.9,
        "daily_sales_date": "2019-02-23T00:00:00"
    },
    {
        "RowInsertDateTime": "2019-02-22T23:50:07.167",
        "ServerName": "P781S001",
        "StoreName": "PRICELINE WERRIBEE",
        "daily_sales": 9989.46,
        "daily_sales_date": "2019-02-22T00:00:00"
    },
    {
        "RowInsertDateTime": "2019-02-21T23:50:06.98",
        "ServerName": "P781S001",
        "StoreName": "PRICELINE WERRIBEE",
        "daily_sales": 10120.73,
        "daily_sales_date": "2019-02-21T00:00:00"
    },
    {
        "RowInsertDateTime": "2019-02-20T23:00:14.46",
        "ServerName": "P781S001",
        "StoreName": "PRICELINE WERRIBEE",
        "daily_sales": 5732.03,
        "daily_sales_date": "2019-02-20T00:00:00"
    }
]

dates = [i['daily_sales_date'] for i in json_data]
values = [i['daily_sales'] for i in json_data]
print('sample date: ' + dates[0])
print('sample value: ' + str(values[0]))

df = pd.DataFrame({'dates':dates, 'values':values})
df['dates']  = pd.to_datetime(df['dates'])  # possibly format="..."
plt.bar(df['dates'].values, df['values'].values)

plt.show()
1 голос
/ 09 апреля 2019

Использовать тиковый локатор :

from matplotlib.dates import MonthLocator

ax.xaxis.set_major_locator(MonthLocator())

Это создаст один тик за каждый месяц. См. документы для получения дополнительных настроек.

0 голосов
/ 09 апреля 2019

Вы можете показывать только каждую n-ю дату, чтобы уменьшить беспорядок:

ticks = ax.get_xticks()
labels = ax.get_xticklabels()
n = len(ticks) // 10  # Show 10 ticks.
ax.set_xticks(ticks[::n])
ax.set_xticklabels(labels[::n])
...