Skip to article frontmatterSkip to article content

Trial Jupyter Notebook

University of Kansas
import numpy as np
from numpy import random
import pandas as pd

# make random data and their indices
nData = 150
mu = 5
sigma = 3
random_numbers = mu + sigma*random.normal(0, 1, size=nData)
times = np.arange(1, nData+1)

# make it a pandas dataframe
df = pd.DataFrame(
    {"ratio": random_numbers,
    "time":  times})
import altair as alt

chart = alt.Chart(df)

points = chart.mark_point(color='darkBlue', filled=True).encode(
    alt.X('time').title("mass spec index").axis(grid=False).scale(domain=(0,180), clamp=True),
    alt.Y('ratio').axis(grid = True).scale(clamp=True)
).interactive()

meanline = chart.mark_rule(color='red', strokeWidth=2).encode(
    alt.Y("mean(ratio)").title("206Pb/205Pb")
)

hist = chart.mark_bar().encode(
     alt.X('ratio').bin(maxbins=10).title("206Pb/205Pb"),
     alt.Y('count()').title("Count").axis(orient='right')
)

text = meanline.mark_text(
    align = "right",
    baseline = "bottom", 
    dx = 200-1,
).encode(text = "mu:Q").transform_calculate(
    mu = alt.expr.round( 1000 * df["ratio"].mean() ) / 1000
    )

( # plots
    (meanline + points + text).properties(
    width = 400, height = 250,
    title = "206Pb/205Pb")
    |
    hist.properties(
        width = 200, height = 250
    )
)
Loading...