Square Heatmap ticks are off
See original GitHub issueI have plotly 4.1.0 installed and this code (in a Jupyter Notebook):
import numpy as np
import plotly.offline as py
import plotly.graph_objs as go
matrix = np.random.randn(10, 10)
ticks = ["tick %i" % i for i in range(10)]
data = [go.Heatmap(z=matrix, x=ticks, y=ticks, colorscale='Viridis')]
layout = go.Layout(
hovermode='closest',
autosize=True,
xaxis=dict(zeroline=False),
yaxis=dict(zeroline=False, autorange='reversed', scaleanchor="x", scaleratio=1)
)
fig = go.Figure(data=data, layout=layout)
py.iplot(fig)
Produces this plot:
I think there really shouldn’t be this space between the y ticks and colorbar and the heatmap. Without the yaxis scaleanchor="x"
it looks fine, but I really want a square heatmap… Is there any setting I’m missing or is this a bug?
Thanks!
Issue Analytics
- State:
- Created 4 years ago
- Comments:15 (7 by maintainers)
Top Results From Across the Web
How to remove the axis tick marks on a Seaborn heatmap?
Use tick_params() for changing the appearance of ticks and tick labels. Use left=false and bottom=false to remove the tick marks.
Read more >Vertical alignment of y-axis ticks on Seaborn heatmap
I'm plotting a Seaborn heatmap and I want to center the y-axis tick labels, but can't find a way to do this. 'va'...
Read more >seaborn heatmap not displaying correctly
You can work around this without downgrading, if you offset the ticks. For a 2×2 matrix, this works: fig, ax = plt.subplots() cm...
Read more >Heatmap Basics with Seaborn - Towards Data Science
A guide for how to create heatmaps with Matplotlib and Seaborn ... Moving the ticks to the top of the chart would improve...
Read more >seaborn.heatmap — seaborn 0.12.1 documentation
seaborn.heatmap(data, *, vmin=None, vmax=None, cmap=None, center=None, ... cbar=True, cbar_kws=None, cbar_ax=None, square=False, xticklabels='auto', ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Let me also point out the
xaxis.constraintoward: 'right'
option, that - when used withxaxis.constrain: 'domain'
- pushes the whole x axis (and the y-axis ticks with it) over to the right. We never alter the providedheight
andwidth
(exceptautosize
but that only considers external css/page sizing, not the plot contents). So without adjusting the width/height explicitly to match the data there’s no way to satisfy the constraints and automatically end up with no excess whitespace anywhere - But at least withconstraintoward
you’ll have all the plot elements aligned correctly, you just have to remove the large left margin to get the plot you want.Also, be aware that you may specify
constrain
andconstraintoward
for BOTH axes. This is useful in the event you don’t know the aspect ratio of your matrix ahead of time but you always want both x and y tick labels adjacent to the data.https://codepen.io/alexcjohnson/pen/wvwJrqN?editors=0010
That’s weird, that part looks like a bug - in any given situation only one of the two axes should have ended up with a different range than it would have had without the constraint. Perhaps there’s some funny interaction between the constraint and the auto tick rotation that we’re not always dealing with correctly? If you can reproduce it let’s file it over at plotly.js.
Just an update to my first version above… adding
constrain="domain"
to both axes ensures there’s never plot area overflow in either direction.