Issue
I have a collection of dictionaries:
my_dict_1 = {"x=0": 0.33282876064333017, "x=50": 0.3466414380321665, "x=110": 0.3540208136234626, "x=120": 0.350236518448439, "x=130": 0.35042573320719017, "x=140": 0.33415326395458844, "x=150": 0.33245033112582784, "x=450": 0.33345033112582784,}
my_dict_2 = {"x=0": 0.24751431153962036, "x=60": 0.2752335040674902, "x=130": 0.2799035854172944, "x=140": 0.28321783669780054, "x=170": 0.31048508586923773, "x=180": 0.3110876770111479, "x=200": 0.2946670683940946, "x=210": 0.30491111780656827, "x=220": 0.29873455860198855, "x=230": 0.299939740885809, "x=240": 0.3005423320277192, "x=260": 0.29873455860198855, "x=270": 0.2933112383247966, "x=280": 0.2963241940343477, "x=290": 0.2927086471828864, "x=300": 0.2927086471828864, "x=310": 0.2937631816812293, "x=320": 0.2960228984633926, "x=330": 0.2889424525459476, "x=340": 0.28984633925881287, "x=350": 0.28969569147333535, "x=360": 0.2770412774932208, "x=370": 0.26303103344380835, "x=380": 0.27628803856583306, "x=390": 0.2146730943055137, "x=400": 0.2124133775233504, "x=410": 0.2124133775233504}
my_dict_3 = {"x=0": 0.248, "x=50": 0.26, "x=110": 0.281, "x=120": 0.282, "x=130": 0.281, "x=140": 0.292, "x=150": 0.28, "x=160": 0.268, "x=170": 0.274, "x=180": 0.295, "x=190": 0.307, "x=210": 0.28, "x=230": 0.291, "x=240": 0.299, "x=250": 0.266, "x=260": 0.269, "x=270": 0.288, "x=290": 0.283, "x=300": 0.285, "x=310": 0.28, "x=320": 0.243, "x=330": 0.253, "x=340": 0.256, "x=350": 0.246, "x=360": 0.24, "x=370": 0.23, "x=380": 0.228, "x=390": 0.23, "x=400": 0.221, "x=410": 0.222, "x=420": 0.239, "x=430": 0.24, "x=440": 0.222, "x=450": 0.219, "x=460": 0.219, "x=470": 0.219, "x=480": 0.217, "x=490": 0.203, "x=500": 0.214, "x=510": 0.227, "x=520": 0.227, "x=530": 0.209, "x=540": 0.22, "x=550": 0.246, "x=560": 0.226, "x=570": 0.247, "x=580": 0.241, "x=590": 0.267}
I can convert each one to a list with my_dict.values()
, which I can plot with plt.plot(my_dict.values())
.
But how can I set a fixed x axis, say from 0 to 500 with increments of 10, and plot each list's values on the correct x axis' value? I want to plot all lists together on the same plot.
Solution
Try:
for i, d in enumerate([my_dict_1, my_dict_2, my_dict_3], 1):
plt.plot([int(k.split("=")[-1]) for k in d], d.values(), label=f"dict_{i}")
plt.xlabel("X-axis")
plt.ylabel("Y-axis")
plt.title("Three Separate Line Graphs")
plt.legend()
plt.grid()
plt.xlim(0, 500)
plt.xticks(np.arange(0, 501, 10))
plt.show()
Creates this graph:
Answered By - Andrej Kesely
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.