User5
September 19, 2024, 12:38pm
1
Hello everyone ^^,
As you can see in the image below, there’s a margin on the left side. How can I fix this? The image has also another trace, type scatter.
mip_z = np.max(stack, axis=0)
fig = px.imshow(mip_z, zmin=mip_z.min(), zmax=mip_z.max())
fig.add_trace(beads)
fig = fig.update_layout(
coloraxis={"colorscale": color},
margin={"l": 0, "r": 0, "t": 0, "b": 0},
)
# fig = fig.update_yaxes(automargin=False)
fig = fig.update_xaxes(automargin=False, range=[0, mip_z.shape[1]])
fig.update_yaxes(autorange="reversed")
Skiks
September 19, 2024, 5:08pm
2
Hey @User5 !
It’s me again
I guess setting the range to [0, max] should do the trick.
I think the issue is that you set new values to the existing fig
instead of updating the existing one, try:
mip_z = np.max(stack, axis=0)
fig = px.imshow(mip_z, zmin=mip_z.min(), zmax=mip_z.max())
fig.add_trace(beads)
fig.update_layout(
coloraxis={"colorscale": color},
margin={"l": 0, "r": 0, "t": 0, "b": 0},
)
fig.update_xaxes(automargin=False, range=[0, mip_z.shape[1]])
fig.update_yaxes(autorange="reversed")
Skiks
September 19, 2024, 5:10pm
3
Or like I suggested in your other post, try:
fig.update_xaxes(rangemode= "nonnegative")
fig.update_yaxes(autorange="reversed", rangemode= "nonnegative")
User5
September 20, 2024, 7:50am
4
Hey @Skiks ,
Thanks again for your replies.
Unfortunately, it didn’t fix the issue. For some reasons, when I remove the trace which is a go.Scatter object. The image is normal but once I add the trace I see these magins.
fig.update_layout(
coloraxis={"colorscale": color},
margin={"l": 0, "r": 0, "t": 0, "b": 0},
)
# fig = fig.update_yaxes(automargin=False)
fig.update_xaxes(range=[0, mip_z.shape[1]], rangemode="nonnegative",scaleanchor= "y")
fig.update_yaxes(rangemode="nonnegative")
return fig
Skiks
September 20, 2024, 9:19am
5
Hey @User5 !
Weird
Try :
fig.update_xaxes(range=[0, mip_z.shape[0]])
fig.update_yaxes(range=[0, mip_z.shape[1]])
# or if you need to reverse the y axis:
fig.update_yaxes(range=[mip_z.shape[1], 0])
User5
September 20, 2024, 9:22am
6
Hey @Skiks ,
I tried that before but it didn’t work.
I think go.Scatter adds some margins. I don’t know how to remove them.
Skiks
September 20, 2024, 12:09pm
7
@User5 , it seems fine here:
Summary
from dash import dcc, Dash
import plotly.express as px
from skimage import io
app = Dash(__name__)
img = io.imread('https://upload.wikimedia.org/wikipedia/commons/thumb/0/00/Crab_Nebula.jpg/240px-Crab_Nebula.jpg')
fig = px.imshow(img)
x = [i * 50 for i in range(5)]
fig.add_scatter(mode='markers', x=x, y=x, marker_size=10)
fig.update_xaxes(range=[0, img.shape[0]])
fig.update_yaxes(range=[img.shape[1], 0])
app.layout = dcc.Graph(id='cool-graph', figure=fig)
if __name__ == "__main__":
app.run_server(debug=True)
Compare to no ranges set:
User5
September 20, 2024, 12:24pm
8
In my case, I used add_trace(go.Scatter()).
Let me try using add_scatter