leotac / joypy

Joyplots in Python with matplotlib & pandas :chart_with_upwards_trend:
MIT License
559 stars 59 forks source link

Use log transformed x-axis #32

Closed wdecoster closed 5 years ago

wdecoster commented 5 years ago

Thanks for this nice package. I'm looking for a way to use a log10 transformation on the x-axis, and still display the 'right' values as ticklabels.

Things work fine with np.log10 transforming my input data, but then the tick labels don't make sense.

I tried

fig, ax = joypy.joyplot(mydata)
ax.set_xscale('log')

which throws an error because apparently ax is a list, so I tried:

for a in ax:
    a.set_xscale('log')

which throws a ValueError because ValueError: Data has no positive values, and therefore can not be log-scaled.

Do you have suggestions?

wdecoster commented 5 years ago

FWIW I figured out a way on how to do this, but there might be a better way. I transformed the input data using np.log10() and then changed the x labels as:

xticks = [int(i.get_text()) for i in ax[-1].get_xticklabels()]
ax[-1].set_xticklabels([10**i for i in xticks])
leotac commented 5 years ago

As things are, that's probably the easiest thing, though not ideal.

Something you could try is along the lines of:

for a in axes[:-1]:
    a.set_xscale('log')

that avoids the error and should scale the data. But then you still need to manually fix the ticks in the last axis, which is the one that actually shows the ticks and labels.