Skip to content

Instantly share code, notes, and snippets.

@zhaofeng-shu33
Created April 18, 2020 10:58
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 zhaofeng-shu33/2f68f3076f65d5f341400934c15fef7f to your computer and use it in GitHub Desktop.
Save zhaofeng-shu33/2f68f3076f65d5f341400934c15fef7f to your computer and use it in GitHub Desktop.
draw euclid norm illustration
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(-1, 1, 100)
x_r = np.linspace(1, -1, 100)
f_x = np.concatenate((x, x_r))
powers = [1, 2, 3, 4, 100]
label_str_list = ['$|x|+|y|=1$',
'$x^2+y^2=1$',
'$|x|^3+|y|^3=1$',
'$x^4+y^4=1$',
'$x^{100}+y^{100}=1$']
for j in range(5):
i = powers[j]
y = np.power(1-np.power(np.abs(x),i), 1.0/i)
y_r = -1* np.power(1-np.power(np.abs(x),i), 1.0/i)
f_y = np.concatenate((y, y_r))
plt.plot(f_x, f_y, label=label_str_list[j])
plt.legend()
plt.savefig('euclid.png', transparent=True)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment