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

Bar plots with LogScale don't show up properly #1300

Open
sntgluca opened this issue Mar 17, 2021 · 3 comments · May be fixed by #1375
Open

Bar plots with LogScale don't show up properly #1300

sntgluca opened this issue Mar 17, 2021 · 3 comments · May be fixed by #1375
Assignees
Labels

Comments

@sntgluca
Copy link

sntgluca commented Mar 17, 2021

Hi,

Describe the bug
I can't make Bar plots work using a LogScale scale.
I imagine the problem must be connected with the need for the minimum value of a LogScale be non-negative. It's similar but not the same as #1219.

To Reproduce
Here's a simple working example using a LinearScale:

import bqplot as bq
x = [i*3 for i in list("abc")] 
y = np.abs(np.random.randn(10) * 100)
sc_x = bq.OrdinalScale()
sc_y = bq.LinearScale()
scales = {"x": sc_x, "y": sc_y}

line = bq.Lines(x=x, y=y, scales=scales, marker='circle')
bars = bq.Bars(x=x, y=y, scales=scales, opacities=[0.1])

ax_x = bq.Axis(scale=sc_x, grid_lines="none")
ax_y = bq.Axis(scale=sc_y, grid_lines="none", orientation="vertical")
bq.Figure(marks=[line, bars], axes=[ax_x, ax_y], title="Linear scale")

Screenshot 2021-03-17 at 16 54 53

This example doesn't work at all:

sc_x = bq.OrdinalScale()
sc_y = bq.LogScale()
scales = {"x": sc_x, "y": sc_y}

line = bq.Lines(x=x, y=y, scales=scales, marker='circle')
bars = bq.Bars(x=x, y=y, scales=scales, opacities=[0.1])

ax_x = bq.Axis(scale=sc_x, grid_lines="none")
ax_y = bq.Axis(scale=sc_y, grid_lines="none", orientation="vertical")
bq.Figure(marks=[line, bars], axes=[ax_x, ax_y], title="Empty log scale")

Screenshot 2021-03-17 at 16 55 08

And setting the minimum value for the LogScale leads to weird behaviour:

sc_x = bq.OrdinalScale()
sc_y = bq.LogScale(min=0.1)
scales = {"x": sc_x, "y": sc_y}

line = bq.Lines(x=x, y=y, scales=scales, marker='circle')
bars = bq.Bars(x=x, y=y, scales=scales, opacities=[0.1])

ax_x = bq.Axis(scale=sc_x, grid_lines="none")
ax_y = bq.Axis(scale=sc_y, grid_lines="none", orientation="vertical")
bq.Figure(marks=[line, bars], axes=[ax_x, ax_y], title="Log scale")

Screenshot 2021-03-17 at 16 55 34

Expected behavior
I would expect that Bar plots should be possible using a LogScale, and maybe return an error if the dataset doesn't allow it (if values are non-positive).

Additional context
Tested on bqplot 0.12.20.

Thanks!

@sntgluca
Copy link
Author

Dear all,

Is there anyone who could take a look and give us feedback about this and #1219?

As a user who can't really help with the development, I don't have intention to put pressure but I think the use cases in these tickets are pretty important to be addressed.

@sntgluca
Copy link
Author

sntgluca commented May 15, 2021

Hi,
I was able to make it work in some specific case using type="grouped", and setting base as positive.
The fact that it doesn't work with type="stacked" makes me think that corrections to the base code are necessary, though.

x = [i * 3 for i in list("abc")]
y = np.abs(np.random.randn(10) * 100)

sc_x = bq.OrdinalScale()
sc_y = bq.LogScale()
scales = {"x": sc_x, "y": sc_y}

bars = bq.Bars(x=x, y=y, scales=scales, opacities=[0.1], type="grouped", base=1)

ax_x = bq.Axis(scale=sc_x, grid_lines="none")
ax_y = bq.Axis(scale=sc_y, grid_lines="none", orientation="vertical")
bq.Figure(marks=[bars], axes=[ax_x, ax_y], title="Linear scale")

Screenshot 2021-05-15 at 12 12 50

@maartenbreddels
Copy link
Member

I think #1423 fixes this, although I will only work for non-negative values and a non-negative base (see #1423 (comment) )

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

Successfully merging a pull request may close this issue.

3 participants