Reputation: 557
I am using Python 3.6 in Spyder and try to plot a graph with the plotly offline library. Anyways I have some missing dates in my csv-file and I think they cause the problem you can see in the attached screenshot.
Here is my python code:
from plotly.offline import plot
import plotly.graph_objs as go
import pandas as pd
df = pd.read_csv('H://python/final_mk_output_regression.csv')
data = [go.Scatter(
x=df.MESS_DATUM,
y=df['sum_meal'])]
plot(data)
I can not get a correct graph. For example the part before May is very confusing. I have missing dates in my csv-file from 18th April until 30th April which maybe cause this problem. How can I solve this problem?
Upvotes: 1
Views: 6311
Reputation: 61
Only adding type='categry' wouldn't help because it will give unsorted date and time. You will also need to add categoryorder='category ascending'.
Here is the modified code:
data = [go.Scatter(
x=df.MESS_DATUM,
y=df['sum_meal'])]
layout = dict(
title="timeline meal orders",
xaxis = dict(
type="category",
categoryorder='category ascending'))
fig = dict(data=data, layout=layout)
plot(fig, filename="overview")
Upvotes: 3
Reputation: 557
Simply add type="category" to the code. Here we go:
#PRINT DATA
data = [go.Scatter(
x=df.MESS_DATUM,
y=df['sum_meal'])]
layout = dict(
title="timeline meal orders",
xaxis = dict(
type="category"))
fig = dict(data=data, layout=layout)
plot(fig, filename="overview")
Upvotes: 4