How can I add the numbers of observations per group to a boxplot with altair?
I am looking for something like this:
But I am also open to other solutions (as long as the information is visible).
For instance, how would I add this information to the example plot from here?
import altair as alt
from vega_datasets import data
source = data.population.url
alt.Chart(source).mark_boxplot(extent='min-max').encode(
x='age:O',
y='people:Q'
)
Thank you so much for your help!
You cannot dynamically modify titles in Altair/Vega-Lite, so you would need to add a text mark with this information. Something like this (just a proof of principal, you would likely add some explanatory text and make it prettier):
import altair as alt
from vega_datasets import data
source = data.population.url
boxes = alt.Chart(source).mark_boxplot(extent='min-max').encode(
x='age:O',
y='people:Q'
)
boxes + boxes.mark_text().encode(
y=alt.datum(11_500_000),
text='count()'
)
Two other options are to make the sizes of the boxes correspond to the count or add it as the tooltip.
Related
x axis is the width of curtain
y axis is the height of curtain
55,65,75,85 are the price value in $(dollar)
can anyone guide me step by step to import excel into MySQL database with fields
You can take a look onto this package
https://laravel-excel.com/
I use this in all my excel-related projects and it works very well.
check
https://docs.laravel-excel.com/3.1/getting-started/installation.html
use with heading for easy import
I'm designing an app with PySimpleGui, and I want to create a table that looks something like this:
I was able to create a table with the appropriate column headings, but I can't find anything in the docs about how to display grid lines or set the background color for individual columns. Is there a way to do this?
I am trying to make a chart like the following in VL/Altair:
In this example, the X axis labels function like VL headers as far as I can tell. In VL/Altair, the headers are automatically set to the top of each subplot (e.g., this chart).
What is the recommended way of creating a grouped bar chart like this where the headers are located at the bottom?
If I work from this VL example, I can use "labelPadding" to move the headers down below but would like to know if there is a better way of accomplishing this without hard coded values (I've tried other options from the header docs but it seems that headers really prefer to be above the subplots, unless I've missed something):
"column": {"type": "nominal", "field": "site", "header": {"labelPadding": -320}}
You can set the location of the header title and labels using labelOrient and titleOrient properties of the column's header.
Modifying the grouped bar chart example you linked to, it might look something like this:
import altair as alt
from vega_datasets import data
source = data.barley()
alt.Chart(source).mark_bar().encode(
x=alt.X('year:O',
axis=alt.Axis(title=None, labels=False)),
y='sum(yield):Q',
color='year:N',
column=alt.Column('site:N',
header=alt.Header(titleOrient='bottom', labelOrient='bottom'))
)
I am using python spyder, Python v. 3, I need to color format the pandas DataFrame table and export it into HTML or image file, in case if export to image, how to make the image height and width of the table and set appropriate font size.
Could someone please help me on this.
What may be of help is Styler available in pandas. Have a look at the tutorial. Without MCVE it is difficult to answer more precisely.
The HTML output is covered by this question: Python Pandas Data Frame save as HTML page
I need the legend table to have multiple columns instead of one. And I want to add headers to it.
What is the best way to do that?
(I know it's not common, But in this case, each data series has it's own record of information.)
Thanks.
See the documentation:
The legend property of the options has a number of columns property (noColumns). In addition you can specify your own container and/or a labelFormatter function to customize the legend (for example use an empty <table> as container and generate <tr>/<td> elements in the formatter function).
If that is not enough you could let flot build the default legend and then rearrange and customize it afterwards.