2

So I have some 3D data that I am able to plot just fine except the edges look jagged.

The relevant code:

import numpy as np
from matplotlib import cm
from matplotlib import pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

x = np.arange(-1, 1, 0.01)
y = np.arange(-1, 1, 0.01)
x, y = np.meshgrid(x, y)
rho = np.sqrt(x**2 + y**2)

# Attempts at masking shown here
# My Mask
row=0
while row<np.shape(x)[0]:
    col=0
    while col<np.shape(x)[1]:
        if rho[row][col] > 1:
            rho[row][col] = None
        col=col+1
    row=row+1

# Calculate & Plot
z = rho**2
fig = plt.figure()
ax = fig.gca(projection='3d')
surf = ax.plot_surface(x, y, z, rstride=8, cstride=8,  cmap=cm.bone, alpha=0.15, linewidth=0.25)
plt.show()

Produces: Jagged Edges This is so close to what I want except the edges are jagged.

If I disable my mask in the code above & replace it with rho = np.ma.masked_where(rho > 1, rho) it gives: Single Liner Plot

It isn't jagged but not want I want in the corners.

Any suggestions on different masking or plotting methods to get rid of this jaggedness?

4

1 回答 1

1

您是否考虑过使用极坐标(如本例中)?

就像是:

import numpy as np
from matplotlib import cm
from matplotlib import pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

# create supporting points in polar coordinates
r = np.linspace(0,1.25,50)
p = np.linspace(0,2*np.pi,50)
R,P = np.meshgrid(r,p)
# transform them to cartesian system
x, y = R * np.cos(P), R * np.sin(P)

rho = np.sqrt(x**2 + y**2)

# Calculate & Plot
z = rho**2
fig = plt.figure()
ax = fig.gca(projection='3d')
surf = ax.plot_surface(x, y, z, rstride=1, cstride=1,  cmap=cm.bone, alpha=0.15, linewidth=0.25)
plt.show()

在此处输入图像描述

于 2013-10-20T23:51:06.397 回答