Skip to content
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

Incorrect mpld3 plotting in log scale #227

Open
sheldonpark opened this issue Aug 7, 2014 · 7 comments
Open

Incorrect mpld3 plotting in log scale #227

sheldonpark opened this issue Aug 7, 2014 · 7 comments
Labels

Comments

@sheldonpark
Copy link

There appears to be an problem plotting in log scale using mpld3 (v 1.3.1). This problem was reported on stackflow (http://stackoverflow.com/questions/25188903/incorrect-mpld3-plotting-in-log-scale?noredirect=1#comment39225554_25188903) and confirmed by another person.

Thanks.
-Sheldon

@jakevdp
Copy link
Collaborator

jakevdp commented Aug 8, 2014

This does look like a bug, and I'm not sure why it's happening.

Here's a minimal snippet of code that reproduces the bug:

import matplotlib.pyplot as plt
import mpld3

x = [1, 10, 100, 1000]
y = [1, 10, 100, 1000]
ax = plt.subplot(xscale='log', yscale='log')
ax.scatter(x, y)
mpld3.show()

I think it has something to do with the translation/offset framework of path collections, but I'm not sure.

Thanks for reporting this!

@jakevdp jakevdp added the bug label Aug 8, 2014
@kpretz
Copy link

kpretz commented Jul 10, 2017

The panning function doesn't also doesn't work for scatterplots when either of the axes is in log scale. This seems to be a problem only for scatter, and not plot. One work around is to use plot instead of scatter.

ax.plot(x, y, marker='o', linestyle='')

rather than

ax.scatter(x, y)

Finally, the axis labels are a bit weird, for instance:
image

@DanielAndreasen
Copy link

DanielAndreasen commented Sep 26, 2017

It's a poor workaround though, if one wants to color the points.

@kpretz
Copy link

kpretz commented Sep 26, 2017

You can set the point colors using the args 'markeredgecolor' and 'markerfacecolor' - so I think it's still a fine workaround. You have nearly all the same control over plot style with plot compared to scatter.

plot docs here: https://matplotlib.org/api/_as_gen/matplotlib.axes.Axes.plot.html

@DanielAndreasen
Copy link

Forgot about that, but not exactly what I mean.

  1. It was not a critique against your suggestion. That suggestion is better than nothing.
  2. I mean to color each point in a different color (according to some value) like: plt.scatter(x, y, c=z), and have a colorbar as well. Not sure if plot can do this.

Anyway, thanks for your respond.

@kpretz
Copy link

kpretz commented Sep 26, 2017

Good point. Thanks for the clarification. Obviously, being able to use both scatter and plot as designed would be ideal.

@nanls
Copy link

nanls commented Nov 28, 2020

The workaround worked fine for me. 🎉

For those who are using mpld3.plugins.PointLabelTooltip to add labels when hovering a point of the scatter plot with something like this:

    import mpld3
    fig, ax = plt.subplots()
    ax.set_xscale('log', basex=10) 
    # because of the log axis, the scatter plot will not work fine
    scatter = ax.scatter(x, y)
    tooltips = mpld3.plugins.PointLabelTooltip(scatter, labels=labels)
    mpld3.plugins.connect(fig, tooltips)

The labels will not work if you only replace scatter by plot. You also need to change something here:

    tooltips = mpld3.plugins.PointLabelTooltip(scatter[0], labels=labels)
    # see here ----------------------------------------^

Hope that helps. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants