Mpld3: Incorrect mpld3 plotting in log scale

Created on 7 Aug 2014  路  7Comments  路  Source: mpld3/mpld3

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

bug

Most helpful comment

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

All 7 comments

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!

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

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

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

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.

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

The workaround worked fine for me. :tada:

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. :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dmiller7115 picture dmiller7115  路  5Comments

jakevdp picture jakevdp  路  4Comments

arnaudrenaud picture arnaudrenaud  路  4Comments

edvakf picture edvakf  路  29Comments

andreatramacere picture andreatramacere  路  8Comments