0% found this document useful (0 votes)
3 views5 pages

Python Code CP Inverted Graph

Uploaded by

queue tea
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views5 pages

Python Code CP Inverted Graph

Uploaded by

queue tea
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

# Terminal-style script

#!/usr/bin/env python3

# -*- coding: utf-8 -*-

"""

Cyclic polarization plot — expanded for T6 / T30 at 20, 40, 80 and 200 µm

Sequence & legend (boxed, lower right):

T6 20 µm → red

T30 20 µm → darkgreen

T6 40 µm → lightgreen

T30 40 µm → blue

T6 80 µm → darkviolet

T30 80 µm → black

T6 200 µm → plum

T30 200 µm → magenta

Assumes the workbook has 16 columns arranged as:

[x_t6_20, y_t6_20, x_t30_20, y_t30_20, x_t6_40, y_t6_40, ... , x_t30_200, y_t30_200]

"""

import os

import pandas as pd

import [Link] as plt

from [Link] import Line2D

# ============================================================

# File path (edit to your actual path)

# ============================================================

file_path = r"D:\Project PHD\Acousticplastic treated results\20UM LAYER\Cyclic Polarization


[Link]"

if not [Link](file_path):
raise FileNotFoundError(f"The file {file_path} does not exist: {file_path}")

# ============================================================

# Read and clean data

# ============================================================

df = pd.read_excel(file_path)

df = [Link](pd.to_numeric, errors="coerce")

# Helper to extract column pairs safely (col index base 0)

def pair(col_idx):

"""Return (x, y) series for column pair starting at col_idx."""

x = [Link][:, col_idx]

y = [Link][:, col_idx + 1]

return x, y

# Map samples to column indices and colors

samples = [

("T-6 20 µm", 0, "red"),

("T-30 20 µm", 2, "darkgreen"),

("T-6 40 µm", 4, "lightgreen"),

("T-30 40 µm", 6, "blue"),

("T-6 80 µm", 8, "darkviolet"),

("T-30 80 µm", 10, "black"),

("T-6 200 µm", 12, "plum"),

("T-30 200 µm", 14, "magenta"),

# ============================================================

# Helper function for log-scale safety & cleaning

# ============================================================

def valid_log_data(x, y):


"""Return x_abs, y where x_abs>0 and both finite (preserve order)."""

xs = [Link](x).astype(float).abs()

ys = [Link](y).astype(float)

mask = [Link]() & [Link]() & (xs > 0) & (~[Link]([float("inf"), float("-inf")])) &
(~[Link]([float("inf"), float("-inf")]))

return xs[mask], ys[mask]

# Prepare data lists for plotting and legend handles

plot_data = []

legend_handles = []

for label, col_idx, color in samples:

x_raw, y_raw = pair(col_idx)

x_clean, y_clean = valid_log_data(x_raw, y_raw)

plot_data.append((x_clean, y_clean, color, label))

legend_handles.append(Line2D([0], [0], color=color, lw=1.6))

# ============================================================

# Plot setup

# ============================================================

[Link](figsize=(11, 6))

[Link]({

"[Link]": "Times New Roman",

"[Link]": 14,

"[Link]": 1.2,

})

lw = 0.9

# Plot each curve (Potential on X, Current on Y)

for x_clean, y_clean, color, label in plot_data:


# Note: user previously used [Link](y, x) — keep same orientation if that matched original figure.

# Here we follow the established orientation: potential (V) on X axis, current density on Y (log
scale).

[Link](y_clean, x_clean, color=color, linewidth=lw, label=label)

# Axes labels and scales (adjust limits if necessary)

[Link]("Potential (V vs. Ag/AgCl)", fontsize=15)

[Link]("Current density (A/cm²)", fontsize=15)

[Link]("log")

# Keep the previous sensible defaults; adjust if your data requires different limits:

[Link]([0.5e-6, 1e-1])

[Link]([-0.9, 1.4])

[Link](fontsize=13)

[Link](fontsize=13)

# ============================================================

# Boxed legend (lower right) — matches reference style

# ============================================================

legend_labels = [s[0] for s in samples]

[Link](

legend_handles,

legend_labels,

loc="lower right",

frameon=True,

fancybox=False,

framealpha=1.0,

edgecolor="black",

facecolor="white",

fontsize=12,
handlelength=2.2,

handletextpad=0.6,

borderpad=0.6

plt.tight_layout()

[Link]()

You might also like