Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
gsmaio opened this issue Dec 15, 2020 · 5 comments
Closed

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

gsmaio opened this issue Dec 15, 2020 · 5 comments

Comments

@gsmaio
Copy link

gsmaio commented Dec 15, 2020

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

@gsmaio gsmaio changed the title fig.add_hline limited from 0 to 1 when rendered with plotly.offline fig.add_vline limited from 0 to 1 when rendered with plotly.offline Dec 15, 2020
@johnml1135
Copy link

johnml1135 commented Feb 4, 2021

I have the same issue [plotting only in row 1 between 0 and 1]. For me though, it appears when I plot in dash. add_vline works fine if I render in Spyder, png or the browser: fig.show('browser')

python 3.8
plotly 4.14.3
dash 1.19.0

@johnml1135
Copy link

I was able to reproduce the error with dash 4.13.0. It appears that it is a bug in the initial implementation of vline/hline in multiple graphs in version 4.12.0 - #2840.

@nicolaskruchten
Copy link
Contributor

See my answer here https://community.plotly.com/t/why-does-the-vertical-line-created-by-add-vline-does-not-extend-indefinetely-on-the-y-axis/49683/3?u=nicolaskruchten ... you'll need to ensure your rendering environment has the latest Plotly.js version. See https://plotly.com/python/troubleshooting/ for details.

@johnml1135
Copy link

johnml1135 commented Feb 5, 2021

From the troubleshooting guide: "first ensure that you have upgraded dash to the latest version, which will automatically upgrade dash-core-components to the latest version, ensuring that Dash is using an up-to-date version of the Plotly.js rendering engine for plotly."

This is not completely true with conda, as upgrading dash does not automatically upgrade dash-core-components (at least in my corporate environment). I had dash-core-components 1.3.0 (Oct 2019?) and was able to upgrade to 1.15.0 using:
conda install -c conda-forge dash-core-components==1.15.0

That fixed my issue!

Also, This is related to: https://community.plotly.com/t/why-does-the-vertical-line-created-by-add-vline-does-not-extend-indefinetely-on-the-y-axis/49683

@gvwilson
Copy link
Contributor

Hi - we are trying to tidy up the stale issues and PRs in Plotly's public repositories so that we can focus on things that are still important to our community. Since this one has been sitting for several years, I'm going to close it; if it is still a concern, please add a comment letting us know what recent version of our software you've checked it with so that I can reopen it and add it to our backlog. Thanks for your help - @gvwilson

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants