Skip to content

Instantly share code, notes, and snippets.

@rakaar
Created May 14, 2020 18:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rakaar/21513ba717179f3f2e257143a057b2bd to your computer and use it in GitHub Desktop.
Save rakaar/21513ba717179f3f2e257143a057b2bd to your computer and use it in GitHub Desktop.
Plot a smooth curve joining the points
import matplotlib.pyplot as plt
import numpy as np
from scipy.interpolate import interp1d
from matplotlib.patches import Ellipse
x = np.array([0.9,1,1.1,1.2,1.3,1.4,1.5,1.6,1.7,1.8])
y = np.array([8,7.2,6,5.5,5,5.2,7.2,9,11.2,12])
x1 = np.array([0.8,0.9,1,1.1,1.2,1.3,1.4,1.5,1.6,1.7,1.8,1.9,2,2.1])
y1 = np.array([9.5,9.2,9,7.5,4,2,0,2,4.2,5,7,9,10,12])
plt.plot(x, y, 'bo', label='experimental-data')
plt.plot(x1,y1,'ro',label = 'nnn')
x_new = np.linspace(x.min(), x.max(),500)
x1_new = np.linspace(x1.min(), x1.max(),500)
f = interp1d(x, y, kind='quadratic')
f1 = interp1d(x1, y1, kind='quadratic')
y_smooth=f(x_new)
y_smooth1=f1(x1_new)
ax = plt.subplot(111)
el = Ellipse((2, -1), 0.5, 0.5)
ann = ax.annotate('25% load',
xy=(1.7, 11.2), xycoords='data',
xytext=(-130, 0), textcoords='offset points',
size=20, va="center",
bbox=dict(boxstyle="round", fc=(0, 0.7, 1), ec="none"),
arrowprops=dict(arrowstyle="wedge,tail_width=1.",
fc=(0, 0.7, 1), ec="none",
patchA=None,
patchB=el,
relpos=(0.2, 0.5)))
ann = ax.annotate('No load',
xy=(1.6, 4.2), xycoords='data',
xytext=(55,0), textcoords='offset points',
size=20, va="center",
bbox=dict(boxstyle="round", fc=(1.0, 0.5, 0.5), ec="none"),
arrowprops=dict(arrowstyle="wedge,tail_width=1.",
fc=(1.0, 0.5, 0.5), ec="none",
patchA=None,
patchB=el,
relpos=(0.2, 0.5)))
plt.xlabel('Field Current')
plt.ylabel('Armature Current')
# joining both minimas
x_min = np.array([1.35,1.4])
y_min = np.array([5,0])
plt.plot(x_min, y_min, color='green', linestyle='dotted', marker='o',
markersize=8)
plt.plot (x_new,y_smooth)
plt.plot(x1_new, y_smooth1)
plt.scatter (x, y)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment