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

Color= makes graph disappear #3721

Open
Notenlish opened this issue Dec 25, 2024 · 2 comments
Open

Color= makes graph disappear #3721

Notenlish opened this issue Dec 25, 2024 · 2 comments
Labels

Comments

@Notenlish
Copy link

What happened?

my data.csv:

Temp_Range,Time,Gross_Final_Mass,Water_Final_Mass,Lost_Mass
40-45,30.1,1246,677,2
40-45 ,28.0,1246,677,2
40-45  ,28.63,1246,677,2
45-50,35.0,1246,677,2
45-50 ,25.0,1246,677,2
45-50  ,30.3,1246,677,2
50-55,29.4,1244,675,4
50-55 ,32.4,1245,676,3
50-55  ,29.2,1243,674,5
55-60,32.3,1242,673,6
55-60 ,32.0,1242,673,6
55-60  ,30.0,1243,674,5
60-65,34.4,1241,672,7
60-65 ,35.2,1241,672,7
60-65  ,29.0,1241,672,7
import polars
import altair as alt

df = polars.read_csv("data.csv")

chart = df.plot.line(
    x="Temp_Range",
    y=alt.Y("Gross_Final_Mass",
        scale=alt.Scale(domain=[1240, 1250])
    )
)

chart.save("gross final mass.png")

Basically, I have a few test results of me heating water in different temperature ranges and I want to create an graph out of it. I had to add a few spaces to the temp ranges otherwise it'd just accept them all as a single value, not multiple values. When I add color="Temp_Range" to there, the lines just disappear for some reason.

here's the output without color=:
Image

here's the output with color=
Image

What would you like to happen instead?

I want the same temperature ranges to have same color, but be colored differently than other temperature ranges(eg: 40-45 is orange, 45-50 is green etc.)

Which version of Altair are you using?

5.5.0

@Notenlish Notenlish added the bug label Dec 25, 2024
@dangotbanned
Copy link
Member

@Notenlish

here's the output with color=

Could you provide the full code block for that please?

E.g. the exact difference from:

Code block

import polars
import altair as alt

df = polars.read_csv("data.csv")

chart = df.plot.line(
    x="Temp_Range",
    y=alt.Y("Gross_Final_Mass",
        scale=alt.Scale(domain=[1240, 1250])
    )
)

chart.save("gross final mass.png")


However I suspect the issue is related to the values in "Temp_Range" itself.

It looks like trailing spaces were added at the source for duplicate "Temp_Range"(s).

 Temp_Range,Time,Gross_Final_Mass,Water_Final_Mass,Lost_Mass
 40-45,30.1,1246,677,2
-40-45 ,28.0,1246,677,2
-40-45  ,28.63,1246,677,2
+40-45,28.0,1246,677,2
+40-45,28.63,1246,677,2
 45-50,35.0,1246,677,2
-45-50 ,25.0,1246,677,2
-45-50  ,30.3,1246,677,2
+45-50,25.0,1246,677,2
+45-50,30.3,1246,677,2
 50-55,29.4,1244,675,4
-50-55 ,32.4,1245,676,3
-50-55  ,29.2,1243,674,5
+50-55,32.4,1245,676,3
+50-55,29.2,1243,674,5
 55-60,32.3,1242,673,6
-55-60 ,32.0,1242,673,6
-55-60  ,30.0,1243,674,5
+55-60,32.0,1242,673,6
+55-60,30.0,1243,674,5
 60-65,34.4,1241,672,7
-60-65 ,35.2,1241,672,7
-60-65  ,29.0,1241,672,7
+60-65,35.2,1241,672,7
+60-65,29.0,1241,672,7

You should be able to fix data.csv after reading like this:

import polars as pl

df = pl.read_csv("data.csv").with_columns(pl.col("Temp_Range").str.strip_chars_end())

Whatever you're using to produce this data, is likely using this column as an index - but is compensating for non-unique values.
You might be able to prevent this at the source with an explicit index?

@FELLIX000
Copy link

Supported

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

3 participants