Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 16536

Problem with built matplotlib contour plot

$
0
0

I have function which set relation between distance and some coefficient. I have build usual plot - there is no problem and I get my coefficien equal max 1. See please code and plot for it.

import numpy as npimport matplotlib.pyplot as pltimport matplotlibmatplotlib.rcParams.update({'font.size': 12})x = np.linspace(0, 8, 800)f1 = 3 * (x/8)**4 - 8 * (x/8)**3 + 6 * (x/8)**2plt.plot(x, f1, ':b', label='1st component')plt.xlabel(r'$x$', fontsize=16)plt.ylabel(r'$f(x)$', fontsize=16)plt.xlim([0, 8])plt.ylim([0, 1.1])plt.legend(fontsize=14)plt.tight_layout()plt.show()

[enter image description here](https://i.stack.imgur.com/rZiNT.jpg)

And now I need apply this function for surface for every azimut direction. For this I would like use contour plot.

First of all, as this coefficient dont changing for every azimut I expect that it wil be same i.e. circle, second - my function should give me coefficient max 1. But I get strange plot and k max = 1.44.

import numpy as npimport matplotlib.pyplot as pltimport matplotlibxx = np.linspace(-8, 8, 100)yy = np.linspace(-8, 8, 100)X, Y = np.meshgrid(xx, yy)ZX = 3 * (abs(X)/8)**4 - 8 * (abs(X)/8)**3 + 6 * (abs(X)/8)**2ZY = 3 * (abs(Y)/8)**4 - 8 * (abs(Y)/8)**3 + 6 * (abs(Y)/8)**2Z = np.sqrt(np.square(ZX) + np.square(ZY))cs = plt.contour(X, Y, Z, 20, cmap='rainbow')plt.clabel(cs)plt.colorbar()plt.grid(which='major')plt.title('Contours Plot')plt.xlabel('X (m)')plt.ylabel('Y (k)')plt.tight_layout()plt.show()

enter image description here

Could you please explain how I can apply my function for the surface via matplotlib contour that get circle and max coef = 1?


Viewing all articles
Browse latest Browse all 16536

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>