【FreeCAD初心者ガイド】FreeCAD付属のmatplotlibを使って3次元モデリングに便利なプロトタイプ関数を思索する
※ 当ページには【広告/PR】を含む場合があります。
2023/10/06

FreeCADでmatplotlibを使うための基本操作

[マクロ]
[マクロの実行]
[ユーザーマクロの場所]
[作成]
[OK]
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(-2*np.pi, 2*np.pi, 100)
y = np.sin(x)
plt.plot(x,y)
plt.show()

FreeCADで2次元グラフを描く〜Plotワークベンチ編
Plotワークベンチのインストール



Plotワークベンチを利用して関数を描画する

[表示] > [パネル] > [Pythonコンソール]
from FreeCAD.Plot import Plot
from freecad.plot import Plot
Plot.plot([0, 1], [0, 2])

plot☓
Plotワークベンチでグラフを装飾する
from FreeCAD.Plot import Plot
import numpy as np
t = np.linspace(0, 1, 101)
s = np.sin(2.0*np.pi*t)
c = np.cos(2.0*np.pi*t)
Plot.plot(t,s)
Plot.plot(t,c)


1. 横軸/縦軸の表示範囲を調整
2. ブロットの線種・点種・配色
3. ラベル(タイトル・x軸・y軸)の文字・フォントサイズ
4. ラベル・レジェンドの表示位置を修正
FreeCADで3次元グラフを描く
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure()
ax = fig.add_subplot(projection="3d")
z = np.linspace(0, 10, 2)
theta = np.linspace(-np.pi, np.pi, 5)
Theta, Z = np.meshgrid(theta, z)
r0 = 10
X = r0 * np.cos(Theta)
Y = r0 * np.sin(Theta)
ax.plot_wireframe(X, Y, Z, color='darkblue')
plt.show()

from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure()
ax = fig.add_subplot(projection="3d")
z = np.linspace(0, 10, 5)
theta = np.linspace(-np.pi, np.pi, 100)
Theta, Z = np.meshgrid(theta, z)
r0 = 10
X = r0 * np.cos(Theta)
Y = r0 * np.sin(Theta)
ax.plot_wireframe(X, Y, Z, color='darkblue')
plt.show()

まとめ
記事を書いた人
ナンデモ系エンジニア
電子工作を身近に知っていただけるように、材料調達からDIYのハウツーまで気になったところをできるだけ細かく記事にしてブログ配信してます。
カテゴリー