-
Notifications
You must be signed in to change notification settings - Fork 0
Legend In Plots #119
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
base: main
Are you sure you want to change the base?
Legend In Plots #119
Conversation
I prefer, in order:
|
The problem I am having is when I do independent I tried querying AI somewhat on this but it wasn't able to help really and propered solutions that did not work / were seemingly not sensible. I will keep at it. |
I don't think there is any way for the transparencies to match the legend. By definition the 50% CI is overlayed on top of the the 90%, etc. The legend will have no concept of this. We could swap to different colors for each band to resolve this. To mimic the R plots, use |
Sounds great. This commit 7185da2 was clean and had Forecast in steelblue wo/ actual CI labels, but what you just suggested sounds better. |
@AFg6K7h4fhy2 I suggest getting the colors programmatically with >>> import colorbrewer
... colorbrewer.Blues[3]
[(222, 235, 247), (158, 202, 225), (49, 130, 189)] |
hubverse_annotator/utils.py
Outdated
labels = [f"{round((high - low) * 100)}% CI" for low, high in ci_pairs] | ||
|
||
palette_rgb255 = list( | ||
colorbrewer.Blues[max(3, min(MAX_NUM_CIS, len(labels)))] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MAX_NUM_CIS
is not used to limit ci_pairs
. Seems like an oversight.
hubverse_annotator/utils.py
Outdated
palette_rgb255 = list( | ||
colorbrewer.Blues[max(3, min(MAX_NUM_CIS, len(labels)))] | ||
) | ||
palette = [(r / 255, g / 255, b / 255) for r, g, b in palette_rgb255] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This approch, using rgb_strings, feels more straightforward than division + hex conversion.
import altair as alt
import polars as pl
import colorbrewer
rgb_tuples = colorbrewer.Blues[3]
rgb_strings = [f"rgb({r},{g},{b})" for r, g, b in rgb_tuples]
df = pl.DataFrame({
'x': [1, 2, 3],
'y': [4, 5, 6]
})
chart = alt.Chart(df).mark_point(
color=rgb_strings[2],
size=100
).encode(
x='x',
y='y'
)
chart
hubverse_annotator/utils.py
Outdated
"low": f"{low:.3f}".rstrip("0").rstrip("."), | ||
"high": f"{high:.3f}".rstrip("0").rstrip("."), | ||
"color": to_hex(color), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, let's use format_percent
from babel
.
bands = [ | ||
band("0.025", "0.975", 0.10), | ||
band("0.1", "0.9", 0.20), | ||
band("0.25", "0.75", 0.30), | ||
band(spec["low"], spec["high"], label) | ||
for label, spec in ci_specs.items() | ||
if spec["low"] in df_wide.columns and spec["high"] in df_wide.columns |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Structure overall feels a bit off.
What about
- We have
get_available_ci(list_of_quantiles)
which returns all of the available ci's (width only, or width, lower, and upper) - Then somewhere later we have the availability to subsample the available ci's (either by giving the list of widths we want or by limiting to some max number).
- Then we get the colors based on the length of the subsampled list of ci's.
- Then we make the plot with legend.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will try this out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Get the colors" step may be obviated by https://vega.github.io/vega/docs/schemes/#blues
hubverse_annotator/utils.py
Outdated
from typing import Literal | ||
|
||
import altair as alt | ||
import colorbrewer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than colorbrewer, we should try to take advantage of https://vega.github.io/vega/docs/schemes/#blues
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The output looks good, but I think we can make the internals better.
hubverse_annotator/utils.py
Outdated
] | ||
|
||
num_colors = max(3, min(MAX_NUM_CIS, len(labels))) | ||
blues_map = colormaps["Blues"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought the plan was to use vega's built-in implementation of the blues palette. Is there some reason that doesn't work? https://vega.github.io/vega/docs/schemes/#blues
For the full scope of this PR, please refer to issue #117 .
Specifically, this PR adds: