I have a dataframe like the following:
ID Parm_1 Parm_2 Result
0 100 100 0.2
1 100 200 0.4
3 100 300 0.9
4 100 400 0.45
5 200 100 0.01
6 200 200 ...
7 200 300 ...
8 200 400 ...
9 300 100 ...
As you can see there is a repeating sequence with Parm_1
and Parm_2
; when Parm_1
increases, the same 4 Parm_2
values are cycled. However, I don't know how to represent this with matplotlib. I want to draw this where the x-axis shows this increment, as the (crude) drawing shows below.
Any ideas?
Thanks in advance
I have a dataframe like the following:
ID Parm_1 Parm_2 Result
0 100 100 0.2
1 100 200 0.4
3 100 300 0.9
4 100 400 0.45
5 200 100 0.01
6 200 200 ...
7 200 300 ...
8 200 400 ...
9 300 100 ...
As you can see there is a repeating sequence with Parm_1
and Parm_2
; when Parm_1
increases, the same 4 Parm_2
values are cycled. However, I don't know how to represent this with matplotlib. I want to draw this where the x-axis shows this increment, as the (crude) drawing shows below.
Any ideas?
Thanks in advance
Share Improve this question edited Mar 16 at 18:54 President James K. Polk 42.1k29 gold badges109 silver badges145 bronze badges asked Mar 12 at 15:38 pb.pb. 1351 silver badge7 bronze badges 1- Are you aware that you can plot your data as a heatmap? – gboffi Commented Mar 17 at 8:03
1 Answer
Reset to default 0import random
import pandas as pd
import matplotlib.pyplot as plt
data = [(a * 100, b * 100, random.random()) for a in range(1,4) for b in range(1,5)]
df = pd.DataFrame(data, columns=["Parm_1", "Parm_2", "Result"])
fig, ax = plt.subplots(figsize=(8, 5))
ax.plot(df.index, df["Result"], "o")
unique_parm1 = df["Parm_1"].unique()
major_ticks = [df[df["Parm_1"] == p].index[0] -0.5 for p in unique_parm1]
ax.set_xticks(major_ticks, labels=[str(p) for p in unique_parm1], minor=False)
ax.tick_params(axis="x", which="major", length=15, width=2)
ax.set_xticks(df["Parm_2"].index, labels=[str(p) for p in df["Parm_2"]], minor=True)
ax.tick_params(axis="x", which="minor", length=5)
plt.show()