-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
add_hline and add_vline (+add_vrect/add_hrect) #2141
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
Comments
Related to #2140 |
A quick solution would be:
|
Though an issue arrises if you want to add both an x and y line, the second update will overwrite the former and you only see the last added line. As a workaround for that :
So now I see why you referred to this current usage as a bit clunky |
Well we have But what I'm hoping for is a way to have a single function call |
I would also ask that you consider the ability to add text to the upcoming "add_hline" and "add_vline" items. |
There should also be an option to resize v/h lines to fit the plot's min and max y/x axis respectively. I notice that when I add a vline over an existing plot, it runs off the plot (as I presume is happening in the screenshots provided in this thread plotly/plotly_express#143) |
@nicholas-esterer let's start with this issue for now, without tackling the "all subplots" or "one row of subplots" just yet. Let's do the easy case to get going. cc @emmanuelle |
Let's do the "hard version" with the multi-subplot targeting as part of #2140 |
@MrPaulAR we'll see what we can do about adding text. The underlying shapes mechanism doesn't support text today, so this may have to be done as a separate step with |
while most discussion circles around a sugar api call, can we please have a feature to have a TRUE h/v line? timeseries &co dynamic data shifts around. especially with plotly callbacks i cant jugg the whole figure up/down the server just to extendTrace data. Please add a true horizontal / vertical line property with only one coordinate y and x respectively, since the other is infinitely extending. |
This new API does indeed implement true one-coordinate infinite h/v lines that cannot be panned or zoomed away. |
This has now been released as part of Plotly.py 4.12 ! https://community.plotly.com/t/announcing-plotly-py-4-12-horizontal-and-vertical-lines-and-rectangles/46783 |
@nicolaskruchten is it possible to use the For example, my x-axis data is class-based like fig.update_layout(
shapes=[
dict(
type="line",
xref='x', yref='y',
x0=x_data[5], x1=x_data[5],
y0=0, y1=125,
)
]
) But apparently, this gives different results in Plotly as it does in Dash. Dash This only happened in the latest updates (I used to work with plotly=4.8.0 before this error) I wanted to give the I don't know if I should make a different Issue or not. |
Hi @nathansegers, yes, please do make a separate issue for this :) |
@nicolaskruchten The add_vline and add_hline methods are great, and I would really like to use them, but I have encountered a weird issue, where the line has a length of one. |
@jenna-jordan if you're in JupyterLab you'll need to update your lab extension to v4.12 to get this feature to work as intended, and if you're in VSCode, you'll need to wait for the VSCode extension to be updated to the latest version of the Plotly.js rendering engine, unfortunately. |
@nicolaskruchten I am rendering it with streamlit, actually, so I'm not sure how that effects things. |
@jenna-jordan ah, that explains it. Streamlit bundles plotly.js directly and they'll need to update their version in order to suppor this new feature. |
@nicolaskruchten thanks for those features. Is it possible to draw a legend for those lines? |
No legend entries for shapes at the moment, only for traces. |
@nicolaskruchten Why it was decided to have completely different processing and behavior of the shapes? I guess would be just easier to have the same logic and renderers as you have for traces, but it's just a guess... Now it's lacking legend, turn on/off functions. I am trying to use a fake trace to solve this problem. Thanks in advance! |
I wasn't involved in Plotly development when the original design decisions were made around shapes, but generally speaking, we consider traces to be "data" and shapes to be "annotations" and hence conceptually different things. The legend is itself a form of data-driven annotation so shapes don't contribute to it. For the rest of your questions, a better place to ask them would be our forum at community.plotly.com as in Github we mostly try to keep track of bugs and development-related activities :) |
@nicolaskruchten thanks for the answer. |
Performance issues fig.add_vrect code
Step 0 addition 6.687209367752075 As you can see from the log, performance down. the difference is 32 times!!! I am outputting 82 rectangles in 7 seconds !!! Please, fix the problem. |
|
@nicholas-esterer I have a similar issue where the time for individual calls grows as the number of shapes/vrects grows. It occurs with both The big issue here is that the cumulative time for all the function calls can get quite large for a large number of objects. Thanks for your time and attention with this issue!
|
Thank you for your code. I used it to run some profiling (but I excluded the # add_shapes_profiling.py
from plotly import graph_objects as go
import time
import numpy as np
t_add_shape = []
t_add_vrect = []
fig = go.Figure()
x = 0
for idx in range(0, 100):
x0 = x + np.random.randn()
x1 = x0 + np.random.randn()
x = x1 + np.random.randn()
t_start = time.time()
fig.add_shape(x0=x0, x1=x1, y0=-1000, y1=1000)
t_add_shape.append(time.time()-t_start)
fig = go.Figure()
x = 0
for idx in range(0, 100):
x0 = x + np.random.randn()
x1 = x0 + np.random.randn()
x = x1 + np.random.randn()
t_start = time.time()
fig.add_vrect(x0=x0, x1=x1)
t_add_vrect.append(time.time()-t_start) Then profile with python3 -m cProfile -o /tmp/add_shapes_profile /tmp/add_shapes_profiling.py I used this script to examine functions that were called more than 100 times, and sorted them by their time per call, and printed the number of calls as the last item. # print_profile.py
import pstats
from pstats import SortKey
p = pstats.Stats('/tmp/add_shapes_profile')
timepercall_allcalls=sorted([
(fname,tt/nc,nc) for fname, (cc, nc, tt, ct, callers) in p.stats.items()
],key=lambda t: t[1],reverse=True)
timepercall_allcalls=filter(lambda tup: tup[2] > 100,timepercall_allcalls)
for fname, tt_nc, nc in timepercall_allcalls:
print(fname,'%g' % (tt_nc,), nc) Searching for stuff in the plotly module, it shows where it might be good to optimize. It looks like It would be interesting to do @Ben-Mathews chart but plot the number of calls of these "hot" functions. |
Hi, |
We should add these convenience methods, as the ref=x/ref=paper trick is pretty hard for people to understand.
We'd want to be able to add these to all subplots, one subplot, or possibly a single row or a single column.Moved to #2140We'd also want add_vspan and add_hspan (or vrect/hrect, not set on the names)
The text was updated successfully, but these errors were encountered: