I am using plotly (the offline version) within an IPython notebook and I like it a lot. However I couldn't find a way to plot a vertical line or a vertical band.
The equivalents in matplotlib are:
import matplotlib.plyplot as plt
plt.axvline(x=0)
plt.axvspan(xmin=0, xmax=1)
thanks in advance
You can add shapes to your plotly layout. Shapes can include lines or rectangles. They can also be made unbounded by drawing them relative to the plotting area rather than a particular axis. Have a look through the examples in the plotly shapes docs.
layout = {
'title': "My Chart",
'shapes': [
{ # Unbounded line at x = 4
'type': 'line',
# x-reference is assigned to the x-values
'xref': 'x',
# y-reference is assigned to the plot paper [0,1]
'yref': 'paper',
'x0': 4,
'y0': 0,
'x1': 4,
'y1': 1,
'line': {
'color': 'rgb(55, 128, 191)',
'width': 3,
}
},
{ # Unbounded span at 6 <= x <= 8
'type': 'rect',
# x-reference is assigned to the x-values
'xref': 'x',
# y-reference is assigned to the plot paper [0,1]
'yref': 'paper',
'x0': 6,
'y0': 0,
'x1': 8,
'y1': 1,
'fillcolor': '#d3d3d3',
'opacity': 0.2,
'line': {
'width': 0,
}
}
],
}
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