2017-03-19 6 views
2

私が記入されてmatplotlibの中に円錐曲線をグラフ化しようとしています理想的には、このような何か:。Pythonのmatplotlibの:Graphinc円錐不平等

something like this:

今、私はこのコードを持っている:

import numpy as np 
import matplotlib as mpl 
import matplotlib.pyplot as plt 
import cv2 

mpl.rcParams['lines.color'] = 'k' 
mpl.rcParams['axes.prop_cycle'] =mpl.cycler('color', ['k']) 

x = np.linspace(-9, 9, 400) 
y = np.linspace(-5, 5, 400) 
x, y = np.meshgrid(x, y) 

def axes(): 
    plt.axhline(0, alpha=.1) 
    plt.axvline(0, alpha=.1) 

a, b, c, d, e, f = 1, 0, 1, 0, 0, -2 
axes() 
plt.contour(x, y,(a*x**2 + b*x*y + c*y**2 + d*x + e*y + f), [0], colors='k') 

plt.gca().set_aspect('equal') 
plt.show() 

、それは次のようになります。

and it looks like this:

アイデア?

答えて

0

簡単な解決策は、線の輪郭(contour)の代わりに塗りつぶした輪郭(contourf)を使用することです。

a, b, c, d, e, f = 1, 0, 1, 0, 0, -2 
plt.contourf(x, y,(a*x**2 + b*x*y + c*y**2 + d*x + e*y + f), [f, 0], colors='k') 

完全例

import numpy as np 
import matplotlib.pyplot as plt 

x = np.linspace(-9, 9, 400) 
y = np.linspace(-5, 5, 400) 
x, y = np.meshgrid(x, y) 

plt.axhline(0, alpha=.1, c="k") 
plt.axvline(0, alpha=.1, c="k") 

a, b, c, d, e, f = 1, 0, 1, 0, 0, -2 

plt.contourf(x, y,(a*x**2 + b*x*y + c*y**2 + d*x + e*y + f), [f, 0], colors='k') 

plt.gca().set_aspect('equal') 
plt.show() 

enter image description here