Black Lives Matter. Please consider donating to Black Girls Code today.

X-axis formating with Python

Hello,

I am new to plotly and am trying to create as simple bar graph. Everything loads properly but the x-axis is summarizing my dates and not plotting the specific dates in my list. Any ideas on how to fix this so the x-axis only displays the dates I am passing it.

Here is the snippet of code that gets executed

x_axis = [1885, 1887, 1888, 1913, 1884, 1891, 1892, 1929, 1868, 1896]
y_axis = [12, 10, 9, 8, 7, 7, 7, 7, 6, 6]

graph = [go.Bar(x = x_axis, y = y_axis)]
py.plot(graph, filename=‘bar_graph’)

Set your x axis type to “date”:

type is in the xaxis object, which is in the layout object:

data = [go.Bar(x = x_axis, y = y_axis)]
layout = dict( xaxis = dict( type = "date" )  )
py.plot( { 'data':data, 'layout':layout }, filename='bar_graph' )

Hello Jack,

Thanks for the solution. It seems like I am still seeing the same type of summarization into decades on the x axis. Any ideas?

from plotly.offline import plot
import plotly.graph_objs as go

x_axis = [1885, 1887, 1888, 1913, 1884, 1891, 1892, 1929, 1868, 1896]
y_axis = [12, 10, 9, 8, 7, 7, 7, 7, 6, 6]

data = [go.Bar(x=x_axis, y=y_axis)]
layout = dict(xaxis=dict(type=“date”))
plot({‘data’: data, ‘layout’: layout}, filename=‘bar_graph.html’)