question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Square Heatmap ticks are off

See original GitHub issue

I 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: Screenshot 2019-08-23 at 14 36 18

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:closed
  • Created 4 years ago
  • Comments:15 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
alexcjohnsoncommented, Aug 26, 2019

Let me also point out the xaxis.constraintoward: 'right' option, that - when used with xaxis.constrain: 'domain' - pushes the whole x axis (and the y-axis ticks with it) over to the right. We never alter the provided height and width (except autosize 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 with constraintoward 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 and constraintoward 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

Screen Shot 2019-08-25 at 9 27 16 PM

ah, hah that’s funny: when I exported it showed that in fact it just gives the same problem the other way 😛

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.

1reaction
nicolaskruchtencommented, Sep 26, 2019

Just an update to my first version above… adding constrain="domain" to both axes ensures there’s never plot area overflow in either direction.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found