Python
 Computer >> コンピューター >  >> プログラミング >> Python

Matplotlibを使用して半分黒と半分白の円をプロットする方法は?


Matplotlibを使用して半黒と半白の円をプロットするには、次の手順を実行できます-

  • 図のサイズを設定し、サブプロット間およびサブプロットの周囲のパディングを調整します。
  • 図とサブプロットのセットを作成します。
  • theta1を初期化します およびtheta2 theta1からtheta2に、またはその逆にエッジを描画します。
  • 現在の軸にウェッジインスタンスを追加します。
  • 軸の制限を変更して、等しいスケーリングを設定します。
  • xを設定します およびy スケール。
  • 図を表示するには、 show()を使用します メソッド。

import matplotlib.pyplot as plt
from matplotlib.patches import Wedge

plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True

fig, ax = plt.subplots()
theta1, theta2 = 0, 0 + 180
radius = 2
center = (0, 0)
w1 = Wedge(center, radius, theta1, theta2, fc='black', edgecolor='black')
w2 = Wedge(center, radius, theta2, theta1, fc='white', edgecolor='black')

for wedge in [w1, w2]:
   ax.add_artist(wedge)

ax.axis('equal')
ax.set_xlim(-5, 5)
ax.set_ylim(-5, 5)

plt.show()

出力

Matplotlibを使用して半分黒と半分白の円をプロットする方法は?


  1. MatplotlibでNaN値をプロットして操作する方法は?

    matplotlibでNaN値をプロットして操作するには、次の手順を実行できます- いくつかのNaN値を持つnumpyを使用してデータを作成します。 imshow()を使用します データを画像として、つまり2D通常のラスター上に、カラーマップとデータを使用して表示する方法(手順1から)。 図を表示するには、 show()を使用します メソッド。 例 import numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50]

  2. Matplotlibを使用して2つの点線をプロットし、マーカーを設定するにはどうすればよいですか?

    このプログラムでは、matplotライブラリを使用して2本の線をプロットします。コーディングを開始する前に、まず次のコマンドを使用してmatplotlibライブラリをインポートする必要があります- Import matplotlib.pyplot as plt Pyplotは、matplotlibをMATLABのように機能させるコマンドスタイル関数のコレクションです。 アルゴリズム Step 1: Import matplotlib.pyplot Step 2: Define line1 and line2 points. Step 3: Plot the lines using the p