Breaking News

How to plot Multiple lines of different x and y values by Python (Mathplotlab)

Sometimes we need to plot lines of different values of independent variables (x) or in other words lines with various x and y values; which can not be plotted in MS excel. Instead, it can be done using a few tools like MATLAB, Python etc. Here a simple way of plotting numerous line of variable x and y values are shown using the Mathplotlab module of Python.

# importing package
import matplotlib.pyplot as plt
import numpy as np

# create data

x1= [0, 100, 288.688]
x2= [0, 162.504, 329.026]
x3= [0, 67.312, 257.369]
x4= [0, 48.246, 213.201]
x5= [0, 120, 302.712]

y1= [0, 16454.4043, 20516.6357]
y2= [0, 17065.031, 21855.0766]
y3= [0, 11723.5347,23803.7876]
y4= [0, 12766.6139, 16446.8316]
y5= [0, 16999.2965, 21368.8108]


# plot lines
plt.plot(x1, y1, label = "Model 1", marker='o', c='grey', mfc='c')
plt.plot(x2, y2, label = "Model 2", marker='D', c='red', mfc='c')
plt.plot(x3, y3, label = "Model 3", marker='x', c='green', mfc='c')
plt.plot(x4, y4, label = "Model 4", marker='o', c='orange', mfc='c')
plt.plot(x5, y5, label = "Model 5", marker='s', c='blue', mfc='c')
plt.title("Varations with different type of models")
plt.xlabel("Deflection (Millimeter)")
plt.ylabel("Load (kilonewtons)")
plt.legend()
plt.show()


The output is like this,





No comments