Skip to content

fig.add_vline limited from 0 to 1 when rendered with plotly.offline #2980

Closed
@gsmaio

Description

@gsmaio

The add_vline still have a weird issue, fig.add_hline(x=2) results in a line at 2 on the x axis but only extends from 0 to 1 on the y axis. The problem occurs only when plotly.offline is used to generate the HTML plot, while the problem doesn't occur in the Python Spyder console or using dash.


from plotly.subplots import make_subplots

import plotly.graph_objs as go
import plotly.offline as offline
#import plotly as plotly

import numpy as np


fig = make_subplots(
    rows=2,
    cols=1,
    subplot_titles=list(map(str, range(4))),
    shared_xaxes=True,
    shared_yaxes=False,
)

time = np.linspace(-np.pi, np.pi, 1000)

for i in range(4):
    data = np.sin((i+1) * time)
    fig.add_trace(
        go.Scatter(y=data,x=time, name=str(i)),
        row=1 if i in [0, 1] else 2,
        col=1
    )

fig.add_vline(x=2)            

fig.add_vline(x=1.5, line_dash="dot", row="all", col="all",
  annotation_text="TM(5,3)", 
  annotation_position="top")

fig.show()


#plotly.io.write_image(fig, filenamestr, format='png',scale=None, width=1280, height=800)                                                        
#logMessage("Plot IMG n. "+str(totalPlotCount)+" - "+plotTitle+'.png'+" created in "+str(plotFileAbsPath+'/img/'),q)

offline.plot(fig,                          
                     auto_open=True, image = None, 
                     filename='./prova.html', include_plotlyjs='directory')



import dash
import dash_core_components as dcc
import dash_html_components as html

app = dash.Dash()
app.layout = html.Div([
    dcc.Graph(figure=fig)
])

app.run_server(debug=True, use_reloader=False)  # Turn off reloader if inside Jupyter 

Environment:
Python 3.7
Plotly 4.14.1
dash 1.18.1

Here how it is using plotly.offline to generate the HTML plot (error occurs):
plotly_offline

Here how it looks in the Spyder console:
Python_Spyder-Console

Here how it looks in dash:
Dash_server

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions