I am plotting a horizontal stacked bar chart, and I want each item on the x axis to reflect a datetime value instead of an integer. I am plotting the values in terms of seconds. How can I change the x axis tick labels to reflect a datetime? Thanks!
import plotly.plotly as plt
import plotly.graph_objs as gph
data = [
('task 1', 300),
('task 2', 1200),
('task 3', 500)
]
traces = []
for (key, val) in data:
traces += [gph.Bar(
x=val,
y=1,
name=key,
orientation='h',
)]
layout = gph.Layout(barmode='stack')
fig = gph.Figure(data=traces, layout=layout)
plt.iplot(fig)
Setting the Range of Axes Manually The visible x and y axis range can be configured manually by setting the range axis property to a list of two values, the lower and upper boundary. Here's an example of manually specifying the x and y axis range for a faceted scatter plot created with Plotly Express.
As a general rule, there are two ways to add text labels to figures: Certain trace types, notably in the scatter family (e.g. scatter , scatter3d , scattergeo etc), support a text attribute, and can be displayed with or without markers. Standalone text annotations can be added to figures using fig.
The default font family spec is "Open Sans", verdana, arial, sans-serif , as listed in Python Figure Reference: layout from the Plotly documentation. The precise font selected depends on which fonts you have installed on your system. If Open Sans is available, that font will be selected.
Here is an example (docs)
layout = gph.Layout(
title='Plot Title',
xaxis=dict(
title='x Axis',
titlefont=dict(
family='Courier New, monospace',
size=18,
color='#7f7f7f'
)
),
yaxis=dict(
title='y Axis',
titlefont=dict(
family='Courier New, monospace',
size=18,
color='#7f7f7f'
)
)
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With