예제 #1
0
import pandas as pd

from bokeh.plotting import figure, show
from bokeh.sampledata.periodic_table import elements

elements = elements.copy()
elements = elements[elements.group != "-"]
elements.sort_values('metal', inplace=True)

colormap = {
    "alkali metal"         : "#a6cee3",
    "alkaline earth metal" : "#1f78b4",
    "halogen"              : "#fdbf6f",
    "metal"                : "#b2df8a",
    "metalloid"            : "#33a02c",
    "noble gas"            : "#bbbb88",
    "nonmetal"             : "#baa2a6",
    "transition metal"     : "#e08e79",
}

data=dict(
    atomic_number=elements["atomic number"],
    sym=elements["symbol"],
    name=elements["name"],
    atomic_mass = pd.to_numeric(elements['atomic mass'], errors="coerce"),
    density=elements['density'],
    metal=[x.title() for x in elements["metal"]],
    type_color=[colormap[x] for x in elements["metal"]]
)

mass_format = '{0.00}'
예제 #2
0
import pandas as pd

from bokeh.plotting import figure, show
from bokeh.sampledata.periodic_table import elements

elements = elements.copy()
elements = elements[elements.group != "-"]
elements.sort_values('metal', inplace=True)

colormap = {
    "alkali metal": "#a6cee3",
    "alkaline earth metal": "#1f78b4",
    "halogen": "#fdbf6f",
    "metal": "#b2df8a",
    "metalloid": "#33a02c",
    "noble gas": "#bbbb88",
    "nonmetal": "#baa2a6",
    "transition metal": "#e08e79",
}

data = dict(atomic_number=elements["atomic number"],
            sym=elements["symbol"],
            name=elements["name"],
            atomic_mass=pd.to_numeric(elements['atomic mass'],
                                      errors="coerce"),
            density=elements['density'],
            metal=[x.title() for x in elements["metal"]],
            type_color=[colormap[x] for x in elements["metal"]])

mass_format = '{0.00}'
예제 #3
0
Created on Thu May 30 15:17:41 2019

@author: Administrator
"""

from bokeh.io import output_file, show
from bokeh.plotting import figure
from bokeh.sampledata.periodic_table import elements
from bokeh.transform import dodge, factor_cmap

output_file("periodic.html")

periods = ["I", "II", "III", "IV", "V", "VI", "VII"]
groups = [str(x) for x in range(1, 19)]

df = elements.copy()
df["atomic mass"] = df["atomic mass"].astype(str)
df["group"] = df["group"].astype(str)
df["period"] = [periods[x - 1] for x in df.period]
df = df[df.group != "-"]
df = df[df.symbol != "Lr"]
df = df[df.symbol != "Lu"]

cmap = {
    "alkali metal": "#a6cee3",
    "alkaline earth metal": "#1f78b4",
    "metal": "#d93b43",
    "halogen": "#999d9a",
    "metalloid": "#e08d49",
    "noble gas": "#eaeaea",
    "nonmetal": "#f1d4Af",
예제 #4
0
def report_html_periodic_table(logger, iteration=0):
    # type: (Logger, int) -> ()
    """
    reporting interactive (html) of periodic table to debug samples section
    :param logger: The task.logger to use for sending the plots
    :param iteration: The iteration number of the current reports
    """
    output_file("periodic.html")
    periods = ["I", "II", "III", "IV", "V", "VI", "VII"]
    groups = [str(x) for x in range(1, 19)]
    autompg_clean = elements.copy()
    autompg_clean["atomic mass"] = autompg_clean["atomic mass"].astype(str)
    autompg_clean["group"] = autompg_clean["group"].astype(str)
    autompg_clean["period"] = [periods[x - 1] for x in autompg_clean.period]
    autompg_clean = autompg_clean[autompg_clean.group != "-"]
    autompg_clean = autompg_clean[autompg_clean.symbol != "Lr"]
    autompg_clean = autompg_clean[autompg_clean.symbol != "Lu"]
    cmap = {
        "alkali metal": "#a6cee3",
        "alkaline earth metal": "#1f78b4",
        "metal": "#d93b43",
        "halogen": "#999d9a",
        "metalloid": "#e08d49",
        "noble gas": "#eaeaea",
        "nonmetal": "#f1d4Af",
        "transition metal": "#599d7A",
    }
    source = ColumnDataSource(autompg_clean)
    p = figure(
        plot_width=900,
        plot_height=500,
        title="Periodic Table (omitting LA and AC Series)",
        x_range=groups,
        y_range=list(reversed(periods)),
        toolbar_location=None,
        tools="hover",
    )
    p.rect(
        "group",
        "period",
        0.95,
        0.95,
        source=source,
        fill_alpha=0.6,
        legend_label="metal",
        color=factor_cmap("metal",
                          palette=list(cmap.values()),
                          factors=list(cmap.keys())),
    )
    text_props = {
        "source": source,
        "text_align": "left",
        "text_baseline": "middle"
    }
    x = dodge("group", -0.4, range=p.x_range)
    r = p.text(x=x, y="period", text="symbol", **text_props)
    r.glyph.text_font_style = "bold"
    r = p.text(x=x,
               y=dodge("period", 0.3, range=p.y_range),
               text="atomic number",
               **text_props)
    r.glyph.text_font_size = "8pt"
    r = p.text(x=x,
               y=dodge("period", -0.35, range=p.y_range),
               text="name",
               **text_props)
    r.glyph.text_font_size = "5pt"
    r = p.text(x=x,
               y=dodge("period", -0.2, range=p.y_range),
               text="atomic mass",
               **text_props)
    r.glyph.text_font_size = "5pt"
    p.text(
        x=["3", "3"],
        y=["VI", "VII"],
        text=["LA", "AC"],
        text_align="center",
        text_baseline="middle",
    )
    p.hover.tooltips = [
        ("Name", "@name"),
        ("Atomic number", "@{atomic number}"),
        ("Atomic mass", "@{atomic mass}"),
        ("Type", "@metal"),
        ("CPK color", "$color[hex, swatch]:CPK"),
        ("Electronic configuration", "@{electronic configuration}"),
    ]
    p.outline_line_color = None
    p.grid.grid_line_color = None
    p.axis.axis_line_color = None
    p.axis.major_tick_line_color = None
    p.axis.major_label_standoff = 0
    p.legend.orientation = "horizontal"
    p.legend.location = "top_center"
    save(p)
    logger.report_media("html",
                        "periodic_html",
                        iteration=iteration,
                        local_path="periodic.html")
from bokeh.io import output_file, show
from bokeh.models import ColumnDataSource
from bokeh.plotting import figure
from bokeh.sampledata.periodic_table import elements
from bokeh.transform import dodge, factor_cmap

output_file("periodic.html")

periods = ["I", "II", "III", "IV", "V", "VI", "VII"]
groups = [str(x) for x in range(1, 19)]

df = elements.copy()
df["atomic mass"] = df["atomic mass"].astype(str)
df["group"] = df["group"].astype(str)
df["period"] = [periods[x-1] for x in df.period]
df = df[df.group != "-"]
df = df[df.symbol != "Lr"]
df = df[df.symbol != "Lu"]

cmap = {
    "alkali metal"         : "#a6cee3",
    "alkaline earth metal" : "#1f78b4",
    "metal"                : "#d93b43",
    "halogen"              : "#999d9a",
    "metalloid"            : "#e08d49",
    "noble gas"            : "#eaeaea",
    "nonmetal"             : "#f1d4Af",
    "transition metal"     : "#599d7A",
}

source = ColumnDataSource(df)
def periodic_table():
    periods = ["I", "II", "III", "IV", "V", "VI", "VII"]
    groups = [str(x) for x in range(1, 19)]

    df = elements.copy()
    df["atomic mass"] = df["atomic mass"].astype(str)
    df["group"] = df["group"].astype(str)
    df["period"] = [periods[x - 1] for x in df.period]
    df = df[df.group != "-"]
    df = df[df.symbol != "Lr"]
    df = df[df.symbol != "Lu"]

    cmap = {
        "alkali metal": "#a6cee3",
        "alkaline earth metal": "#1f78b4",
        "metal": "#d93b43",
        "halogen": "#999d9a",
        "metalloid": "#e08d49",
        "noble gas": "#eaeaea",
        "nonmetal": "#f1d4Af",
        "transition metal": "#599d7A",
    }

    source = ColumnDataSource(df)

    p = figure(title="Periodic Table (omitting LA and AC Series)",
               plot_width=600,
               plot_height=300,
               tools="",
               toolbar_location=None,
               x_range=groups,
               y_range=list(reversed(periods)))

    p.rect("group",
           "period",
           0.95,
           0.95,
           source=source,
           fill_alpha=0.6,
           legend="metal",
           color=factor_cmap('metal',
                             palette=list(cmap.values()),
                             factors=list(cmap.keys())))

    text_props = {
        "source": source,
        "text_align": "left",
        "text_baseline": "middle"
    }

    x = dodge("group", -0.4, range=p.x_range)

    r = p.text(x=x, y="period", text="symbol", **text_props)
    r.glyph.text_font_style = "bold"

    r = p.text(x=x,
               y=dodge("period", 0.3, range=p.y_range),
               text="atomic number",
               **text_props)
    r.glyph.text_font_size = "8pt"

    r = p.text(x=x,
               y=dodge("period", -0.35, range=p.y_range),
               text="name",
               **text_props)
    r.glyph.text_font_size = "5pt"

    r = p.text(x=x,
               y=dodge("period", -0.2, range=p.y_range),
               text="atomic mass",
               **text_props)
    r.glyph.text_font_size = "5pt"

    p.text(x=["3", "3"],
           y=["VI", "VII"],
           text=["LA", "AC"],
           text_align="center",
           text_baseline="middle")

    p.add_tools(
        HoverTool(tooltips=[
            ("Name", "@name"),
            ("Atomic number", "@{atomic number}"),
            ("Atomic mass", "@{atomic mass}"),
            ("Type", "@metal"),
            ("CPK color", "$color[hex, swatch]:CPK"),
            ("Electronic configuration", "@{electronic configuration}"),
        ]))

    p.outline_line_color = None
    p.grid.grid_line_color = None
    p.axis.axis_line_color = None
    p.axis.major_tick_line_color = None
    p.axis.major_label_standoff = 0
    p.legend.orientation = "horizontal"
    p.legend.location = "top_center"
    return p
예제 #7
0
def plot_periodic_table():
    output_file("periodic.html")

    occurences = json.load(open('elements.json', 'r'))

    periods = ["I", "II", "III", "IV", "V", "VI", "VII"]
    groups = [str(x) for x in range(1, 19)]

    df = elements.copy()
    df["atomic mass"] = df["atomic mass"].astype(str)
    df["group"] = df["group"].astype(str)
    df["period"] = [periods[x - 1] for x in df.period]
    df = df[df.group != "-"]
    df = df[df.symbol != "Lr"]
    df = df[df.symbol != "Lu"]
    df['occurences'] = [
        f'{round(occurences[x]/occurences["NumCandidates"] * 100, 2)}%'
        for x in df.symbol
    ]
    df['colors'] = [math.log(occurences[x] / 2 + 1) for x in df.symbol]

    p = figure(title="Periodic Table (omitting LA and AC Series)",
               plot_width=1000,
               plot_height=450,
               x_range=groups,
               y_range=list(reversed(periods)))

    #Use the field name of the column source
    mapper = linear_cmap(field_name='colors',
                         palette=bokeh.palettes.Spectral6,
                         low=1,
                         high=max(df.colors))

    r = p.rect("group",
               "period",
               0.95,
               0.95,
               source=df,
               fill_alpha=0.6,
               color=mapper)

    color_bar = ColorBar(color_mapper=mapper['transform'],
                         width=8,
                         location=(0, 0))

    p.add_layout(color_bar, 'right')

    text_props = {
        "source": df,
        "text_align": "left",
        "text_baseline": "middle"
    }

    x = dodge("group", -0.4, range=p.x_range)

    p.text(x=x,
           y="period",
           text="symbol",
           text_font_style="bold",
           **text_props)

    p.text(x=x,
           y=dodge("period", 0.3, range=p.y_range),
           text="atomic number",
           text_font_size="11px",
           **text_props)

    p.text(x=x,
           y=dodge("period", -0.35, range=p.y_range),
           text="name",
           text_font_size="7px",
           **text_props)

    p.text(x=x,
           y=dodge("period", -0.2, range=p.y_range),
           text="occurences",
           text_font_size="7px",
           **text_props)

    p.text(x=["3", "3"],
           y=["VI", "VII"],
           text=["LA", "AC"],
           text_align="center",
           text_baseline="middle")

    p.outline_line_color = None
    p.grid.grid_line_color = None
    p.axis.axis_line_color = None
    p.axis.major_tick_line_color = None
    p.axis.major_label_standoff = 0
    p.legend.orientation = "horizontal"
    p.legend.location = "top_center"
    p.hover.renderers = [r]  # only hover element boxes

    show(p)