Created
April 18, 2020 10:58
-
-
Save zhaofeng-shu33/2f68f3076f65d5f341400934c15fef7f to your computer and use it in GitHub Desktop.
draw euclid norm illustration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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