wex52
wex52

Reputation: 555

Plotly: How do I remove vertical lines that appear after introducing gaps in annotated heatmap?

When I introduce gaps in between bricks in a plotly annotated heatmap, vertical black lines appear behind the bricks (visible in the gaps). The lines appear to line up with the x-axis labels. Even more oddly, if the x-axis category is numeric, the label "0" will not get a vertical line. I want the vertical lines removed. I've looked at the documentation and can't figure out what these lines are. You'll notice that there are also horizontal vertical and white lines that line up with the x- and y-axis labels. I don't mind those.

import plotly.graph_objs as go
from plotly.figure_factory import create_annotated_heatmap
import numpy as np

fig = go.Figure(create_annotated_heatmap(z = np.arange(12).reshape(3,4),
                                         x = [0,1,2,3],
                                         y = ['A','B','C'],
                                         xgap = 30, ygap = 30
                                        )
               )
fig.update_layout(title = 'What are these vertical lines?')
fig.show()

enter image description here

This is not an issue with the standard heatmap:

fig2 = go.Figure(go.Heatmap(z = np.arange(12).reshape(3,4),
                            x = [0,1,2,3],
                            y = ['A','B','C'],
                            xgap = 30, ygap = 30
                           )
                )
fig2.update_layout(title = 'No vertical lines here.')
fig2.show()

enter image description here

Regarding the documentation from help(create_annotated_heatmap), there is a short list of parameters that don't seem to have anything to do with it, and kwargs that go through the standard plotly Heatmap.

Upvotes: 0

Views: 2146

Answers (1)

user11989081
user11989081

Reputation: 8654

The line under the zero is the 'zeroline' while the other lines are the 'gridlines'. They can be removed by setting zeroline=False and showgrid=False in the figure layout.

import plotly.graph_objs as go
from plotly.figure_factory import create_annotated_heatmap
import numpy as np

fig = go.Figure(create_annotated_heatmap(z=np.arange(12).reshape(3,4),
                                         x=[0,1,2,3],
                                         y=['A','B','C'],
                                         xgap=30, ygap=30))

fig.update_layout(xaxis=dict(zeroline=False, showgrid=False), 
                  yaxis=dict(zeroline=False, showgrid=False))

fig.show()

enter image description here Alternatively, you can change their color to white as in the standard heatmap.

import plotly.graph_objs as go
from plotly.figure_factory import create_annotated_heatmap
import numpy as np

fig = go.Figure(create_annotated_heatmap(z=np.arange(12).reshape(3,4),
                                         x=[0,1,2,3],
                                         y=['A','B','C'],
                                         xgap=30, ygap=30))

fig.update_layout(xaxis=dict(zeroline=False, gridcolor='white'),
                  yaxis=dict(zeroline=False, gridcolor='white'))

fig.show()

enter image description here

Upvotes: 2

Related Questions