プロが教えるわが家の防犯対策術!

Q1)下記のコードをPython 3.11.0で旨く実行できる方法があれば、
お教え頂けますと大変有難いです。
====
import numpy as np
import matplotlib.pyplot as plt
#%matplotlib inline
from mpl_toolkits.mplot3d import Axes3D
from scipy.special import gamma
def inverse(z):
return 1/z

def three_D_plot(func,picname):
x, y = np.meshgrid(np.linspace( -5, 5, 500), np.linspace( -5, 5, 500))
z = x + y*1j
w = func(z)
fig = plt.figure()
ax = Axes3D(fig)
ax.plot_surface(x, y, np.abs(w))
ax.set_zlim3d(0, 15.)
ax.autoscale(False)
plt.axis([-6., 6., -6., 6.])
plt.savefig(picname)
print(picname)
plt.show()
#three_D_plot(gamma, "aaa")
three_D_plot(inverse, "aaa")
========
以上、宜しくお願いします。

A 回答 (3件)

私は最近 3D はこの書き方しかしてないです。



fig, ax = plt.subplots(subplot_kw=dict(projection="3d"))

古い書き方ではグラフが描画されないみたいですね。

ちょっと調べてみると MatPlotLib 3.4 以降はこう書くか
fig = plt.figure()
ax = fig.gcs(projection="3d")
とかかないと駄目らしいです。

もっと新しいコードサンプルを使いましょう。
    • good
    • 0
この回答へのお礼

回答有難う御座います。
>私は最近 3D はこの書き方しかしてないです。
fig, ax = plt.subplots(subplot_kw=dict(projection="3d"))
<ーー旨く行きました。
もし出来れば、上記の書き方は何処を参照すれば良いのでしょうか?
以上、宜しくお願いします

お礼日時:2022/12/09 08:27

matplotlibの公式のサンプルページ


https://matplotlib.org/stable/plot_types/index.h …
https://matplotlib.org/stable/gallery/index.html

に3Dのサンプルが沢山ありますが
私と同じ書き方も多いし

ax = plt.figure().add_subplot(projection='3d')

とかも多いです。

宝の山なので是非覗いてみて下さい。
    • good
    • 0
この回答へのお礼

貴重な情報有難う御座いました。

お礼日時:2022/12/09 21:39

>ax = fig.gcs(projection="3d")


訂正
ax = fig.gca(projection="3d")
    • good
    • 0

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!