欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

python+matplotlib演示電偶極子實例代碼

 更新時間:2018年01月12日 10:38:51   投稿:mengwei  
這篇文章主要介紹了python+matplotlib演示電偶極子實例代碼,具有一定借鑒價值,需要的朋友可以參考下

使用matplotlib.tri.CubicTriInterpolator.演示變化率計算:

完整實例:

from matplotlib.tri import (
  Triangulation, UniformTriRefiner, CubicTriInterpolator)
import matplotlib.pyplot as plt
import matplotlib.cm as cm
import numpy as np


#-----------------------------------------------------------------------------
# Electrical potential of a dipole
#-----------------------------------------------------------------------------
def dipole_potential(x, y):
  """ The electric dipole potential V """
  r_sq = x**2 + y**2
  theta = np.arctan2(y, x)
  z = np.cos(theta)/r_sq
  return (np.max(z) - z) / (np.max(z) - np.min(z))


#-----------------------------------------------------------------------------
# Creating a Triangulation
#-----------------------------------------------------------------------------
# First create the x and y coordinates of the points.
n_angles = 30
n_radii = 10
min_radius = 0.2
radii = np.linspace(min_radius, 0.95, n_radii)

angles = np.linspace(0, 2 * np.pi, n_angles, endpoint=False)
angles = np.repeat(angles[..., np.newaxis], n_radii, axis=1)
angles[:, 1::2] += np.pi / n_angles

x = (radii*np.cos(angles)).flatten()
y = (radii*np.sin(angles)).flatten()
V = dipole_potential(x, y)

# Create the Triangulation; no triangles specified so Delaunay triangulation
# created.
triang = Triangulation(x, y)

# Mask off unwanted triangles.
triang.set_mask(np.hypot(x[triang.triangles].mean(axis=1),
             y[triang.triangles].mean(axis=1))
        < min_radius)

#-----------------------------------------------------------------------------
# Refine data - interpolates the electrical potential V
#-----------------------------------------------------------------------------
refiner = UniformTriRefiner(triang)
tri_refi, z_test_refi = refiner.refine_field(V, subdiv=3)

#-----------------------------------------------------------------------------
# Computes the electrical field (Ex, Ey) as gradient of electrical potential
#-----------------------------------------------------------------------------
tci = CubicTriInterpolator(triang, -V)
# Gradient requested here at the mesh nodes but could be anywhere else:
(Ex, Ey) = tci.gradient(triang.x, triang.y)
E_norm = np.sqrt(Ex**2 + Ey**2)

#-----------------------------------------------------------------------------
# Plot the triangulation, the potential iso-contours and the vector field
#-----------------------------------------------------------------------------
fig, ax = plt.subplots()
ax.set_aspect('equal')
# Enforce the margins, and enlarge them to give room for the vectors.
ax.use_sticky_edges = False
ax.margins(0.07)

ax.triplot(triang, color='0.8')

levels = np.arange(0., 1., 0.01)
cmap = cm.get_cmap(name='hot', lut=None)
ax.tricontour(tri_refi, z_test_refi, levels=levels, cmap=cmap,
       linewidths=[2.0, 1.0, 1.0, 1.0])
# Plots direction of the electrical vector field
ax.quiver(triang.x, triang.y, Ex/E_norm, Ey/E_norm,
     units='xy', scale=10., zorder=3, color='blue',
     width=0.007, headwidth=3., headlength=4.)

ax.set_title('Gradient plot: an electrical dipole')
plt.show()

總結

以上就是本文關于python+matplotlib演示電偶極子實例代碼的全部內容,希望對大家有所幫助。感興趣的朋友可以繼續(xù)參閱本站其他相關專題,如有不足之處,歡迎留言指出。感謝朋友們對本站的支持!

相關文章

  • 基于Python實現(xiàn)文件的壓縮與解壓縮

    基于Python實現(xiàn)文件的壓縮與解壓縮

    在日常工作中,除了會涉及到使用Python處理文本文件,有時候還會涉及對壓縮文件的處理。本文為大家總結了利用Python可以實現(xiàn)的幾種文件壓縮與解壓縮實現(xiàn)代碼,需要的可以參考一下
    2022-03-03
  • python實現(xiàn)截取屏幕保存文件,刪除N天前截圖的例子

    python實現(xiàn)截取屏幕保存文件,刪除N天前截圖的例子

    今天小編就為大家分享一篇python實現(xiàn)截取屏幕保存文件,刪除N天前截圖的例子,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2019-08-08
  • python 爬蟲基本使用——統(tǒng)計杭電oj題目正確率并排序

    python 爬蟲基本使用——統(tǒng)計杭電oj題目正確率并排序

    這篇文章主要介紹了python 爬蟲基本的基本使用,主要利用了Urllib和BeautifulSoup4這兩個庫,配以簡單的實例幫助大家理解,感興趣的朋友可以了解下
    2020-10-10
  • Tensorflow2.10實現(xiàn)圖像分割任務示例詳解

    Tensorflow2.10實現(xiàn)圖像分割任務示例詳解

    這篇文章主要為大家介紹了Tensorflow2.10實現(xiàn)圖像分割任務示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2023-01-01
  • Python?asyncio的一個坑

    Python?asyncio的一個坑

    這篇文章主要介紹了Python?asyncio的一個坑,文章從Python編程錯誤開始介紹,改變與好多變不成中常犯的錯誤,我們今天就來分析分析吧,需要的下伙伴也可以參考一下
    2021-12-12
  • Tensorflow 卷積的梯度反向傳播過程

    Tensorflow 卷積的梯度反向傳播過程

    今天小編就為大家分享一篇Tensorflow 卷積的梯度反向傳播過程,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-02-02
  • python常見排序算法基礎教程

    python常見排序算法基礎教程

    這篇文章主要為大家詳細介紹了python算法的基礎教程,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-04-04
  • python在windows調用svn-pysvn的實現(xiàn)

    python在windows調用svn-pysvn的實現(xiàn)

    本文主要介紹了python在windows調用svn-pysvn的實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2023-02-02
  • Python實現(xiàn)將Excel轉換成為image的方法

    Python實現(xiàn)將Excel轉換成為image的方法

    今天小編就為大家分享一篇Python實現(xiàn)將Excel轉換成為image的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-10-10
  • python 利用pyttsx3文字轉語音過程詳解

    python 利用pyttsx3文字轉語音過程詳解

    這篇文章主要介紹了python 利用pyttsx3文字轉語音過程詳解,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
    2019-09-09

最新評論