<jupyter_start><jupyter_text>Re-plot the figure of exploration of phases<jupyter_code>%run -i startup2.py
plt.style.use("/Users/sst/PycharmProjects/bg-mpl-stylesheets/bg_mpl_stylesheet/bg_mpl_stylesheet")
DF = pd.read_csv("data_info.csv", index_col=0)<jupyter_output><empty_output><jupyter_text>Get the data in a matrix<jupyter_code>def create_diff_mat():
    # read one phase fitting Rw
    rws0 = []
    samples = ["JBNP31", "JBNP32", "JBNP33L", "JBNP33"]
    phases = ["Anatase", "Rutile", "Brookite", "PbO2a"]
    for sample in samples:
        csv = DF.loc[sample, "csv2"]
        df = pd.read_csv(csv, index_col=0)
        rws0.append(df.loc["Rw", "val"])
    rws0 = np.array(rws0)

    # get a matrix of rw of two phase
    mat = []
    for sample in samples:
        row = []
        for col in ["csv_ana", "csv_rut", "csv_bro", "csv_pbo"]:
            csv = DF.loc[sample, col]
            df = pd.read_csv(csv, index_col=0)
            row.append(df.iloc[0, 0])
        mat.append(row)
    mat = np.array(mat)

    # get a matrix of difference of rw between two phase and one phase
    def sub_col(col: np.array) -> np.array:
        return col - rws0

    diffmat = np.apply_along_axis(sub_col, 0, mat).T
    return diffmat
diffmat = create_diff_mat()<jupyter_output><empty_output><jupyter_text>Bar plot<jupyter_code>df = pd.DataFrame(diffmat.T, index=["T160", "T130", "T190L", "T190"], columns=["Anatase", "Rutile", "Brookite", "PbO2a"]).sort_index()
df
fig, ax = plt.subplots()
df.plot.bar(ax=ax)
ax.set_xlabel("sample")
ax.set_ylabel("$R_w$")
ax.legend(title="secondary phase")
plt.show()
paper_exporter("second_phase_bar_plot.pdf", fig=fig)<jupyter_output><empty_output><jupyter_text>Matrix plot<jupyter_code># plot mat as color
def visualize_diff_mat():
    fig, ax = plt.subplots()
    xticks = ["T160", "T130", "T190L", "T190"]
    yticks = ["Anatase", "Rutile", "Brookite", "PbO2a"]
    img = ax.imshow(diffmat, cmap="seismic", vmin=-.09, vmax=.09)
    ax.set_xticks([-0.5, 0, 1, 2, 3, 3.5])
    xticks = [""] + xticks + [""]
    ax.set_xticklabels(xticks)
    ax.set_yticks([-0.5, 0, 1, 2, 3, 3.5])
    yticks = [""] + yticks + [""]
    ax.set_yticklabels(yticks)
    plt.colorbar(img)

    # add number to pixel
    width, height = diffmat.shape
    for x in range(width):
        for y in range(height):
            val = diffmat[x, y]
            plt.annotate(f"{val:.3f}", xy=(y, x),
                        horizontalalignment='center',
                        verticalalignment='center',
                        color= "g" if val <= 0 else "r")
    return fig
fig = visualize_diff_mat()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16048448145344435, 'fraction_numerical': 0.026495079485238455, 'mean_word_length': 3.1952380952380954, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '276803', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 1084, 'n_tokens_neox': 1009, 'n_words': 209, 'path': 'analysis8.ipynb', 'repo_name': 'st3107/19st_tio2b_notebooks', 'size': '2642'}