Matplotlib-Funktionen für Dreiecksnetze und Polarkoordinaten


Matplotlib 参考文档Matplotlib-Referenzdokumentation

Funktionen für Dreiecksnetze werden verwendet, um Daten auf unstrukturierten Gittern darzustellen und zu visualisieren, während Polarkoordinatenfunktionen im Polarkoordinatensystem zeichnen.

Funktionsübersicht

FunktionBeschreibung
triplot()Zeichnen Sie ein Drahtgitter eines unstrukturierten Dreiecksnetzes
tripcolor()Zeichnen Sie ein Pseudofarben-Diagramm auf einem Dreiecksnetz
tricontour()Zeichnen Sie Konturlinien auf einem Dreiecksnetz
tricontourf()Zeichnen Sie gefüllte Konturlinien auf einem Dreiecksnetz
polar()Im Polarkoordinatensystem darstellen (äquivalent zu subplot_kw projection='polar')

Dreiecksnetz-Funktionen

triplot() - Drahtgitternetz

matplotlib.pyplot.triplot(*args, **kwargs)
Axes.triplot(triangulation, **kwargs)
# triangulation: Triangulation 对象(由 x, y 坐标创建)

tripcolor() - Dreiecks-Pseudofarbdarstellung

matplotlib.pyplot.tripcolor(*args, **kwargs)
Axes.tripcolor(triangulation, C=None, **kwargs)

tricontour() / tricontourf() - Dreieckskontur

matplotlib.pyplot.tricontour(*args, **kwargs)
matplotlib.pyplot.tricontourf(*args, **kwargs)
Axes.tricontour(triangulation, C=None, levels=None, **kwargs)
Axes.tricontourf(triangulation, C=None, levels=None, **kwargs)

Beispiel

import matplotlib.pyplot as plt
import matplotlib.tri as tri
import numpy as np

np.random.seed(42)

# Zufällige Streupunkte generieren
n = 200
x = np.random.rand(n) * 4 - 2
y = np.random.rand(n) * 4 - 2
# Funktionswert an jedem Punkt
z = x * np.exp(-x**2 - y**2)

# Delaunay-Triangulation erstellen
triang = tri.Triangulation(x, y)

fig, axes = plt.subplots(2, 2, figsize=(10, 8),
                          layout='constrained')

# Drahtgitter des Dreiecksnetzes
axes[0, 0].triplot(triang, 'k-', linewidth=0.5, alpha=0.5)
axes[0, 0].scatter(x, y, c=z, s=8, cmap='viridis')
axes[0, 0].set_title('triplot() - Netz + Streudiagramm')

# Dreieckiger Pseudofarbplot
tc1 = axes[0, 1].tripcolor(triang, z, cmap='viridis',
                            shading='gouraud')  # Glatte Schattierung
fig.colorbar(tc1, ax=axes[0, 1], label='z-Wert')
axes[0, 1].set_title('tripcolor()')

# Dreieckskontur
tc2 = axes[1, 0].tricontourf(triang, z, levels=12,
                              cmap='RdYlBu')
axes[1, 0].tricontour(triang, z, levels=12,
                       colors='black', linewidths=0.3)
fig.colorbar(tc2, ax=axes[1, 0], label='z-Wert')
axes[1, 0].set_title('tricontourf()')

# Nur Konturlinien
axes[1, 1].tricontour(triang, z, levels=15,
                       cmap='viridis', linewidths=1.5)
axes[1, 1].set_title('tricontour()')

plt.show()

polar() - Polardiagramm

matplotlib.pyplot.polar(*args, **kwargs)
# 等同于:
# plt.subplot(projection='polar')
# ax.plot(theta, r)
ParameterBeschreibung
ThetaWinkel-Array (Bogenmaß)
rRadialabstands-Array

Beispiel

import matplotlib.pyplot as plt
import numpy as np

theta = np.linspace(0, 2*np.pi, 100)

fig, axes = plt.subplots(2, 2, figsize=(10, 10),
    subplot_kw={'projection': 'polar'},
    layout='constrained')

# Rosenkurve r = sin(3θ)
r1 = np.abs(np.sin(3 * theta))
axes[0, 0].plot(theta, r1, 'blue', linewidth=2)
axes[0, 0].set_title('Rosettenkurve: r=|sin(3θ)|')

# Archimedische Spirale r = θ
r2 = Theta
axes[0, 1].plot(theta, r2, 'red', linewidth=2)
axes[0, 1].set_title('Archimedische Spirale: r=θ')

# Kardioide r = 1 + cos(θ)
r3 = 1 + np.cos(theta)
axes[1, 0].fill(theta, r3, alpha=0.5, color='coral')
axes[1, 0].plot(theta, r3, 'red', linewidth=2)
axes[1, 0].set_title('Kardioide: r=1+cos(θ)')

# Mehrere Blütenblätter
r4 = np.sin(4 * theta)
axes[1, 1].fill(theta, np.abs(r4), alpha=0.5, color='purple')
axes[1, 1].plot(theta, np.abs(r4), 'purple', linewidth=2)
axes[1, 1].set_rticks([0.5, 1.0])
axes[1, 1].set_title('4-blättrige Rose: r=|sin(4θ)|')

plt.show()

rgrids() / thetagrids() - Polargitter

matplotlib.pyplot.rgrids(radii=None, labels=None, angle=None,
    fmt=None, **kwargs)
matplotlib.pyplot.thetagrids(angles=None, labels=None, fmt=None,
    **kwargs)

Beispiel

import matplotlib.pyplot as plt
import numpy as np

fig, ax = plt.subplots(subplot_kw={'projection': 'polar'},
                        figsize=(6, 6), layout='constrained')

theta = np.linspace(0, 2*np.pi, 100)
ax.plot(theta, theta/3, linewidth=2)

# Benutzerdefiniertes radiales Gitter
ax.set_rticks([1, 3, 5, 7, 9])      # Positionen der radialen Teilstriche
ax.set_rlabel_position(-22.5)         # Positionen der radialen Beschriftungen

# Benutzerdefiniertes Winkelgitter
ax.set_thetagrids(np.arange(0, 360, 45),  # Alle 45 Grad
                  labels=['0°','45°','90°','135°','180°',
                          '225°','270°','315°'])

ax.set_title('Benutzerdefiniertes Polargitter')
plt.show()

Matplotlib 参考文档Matplotlib-Referenzdokumentation

Andere Erweiterungen