user24353751
user24353751

Reputation: 35

A 3D plot invisible where it overlaps the gray border

Having shifted the origin of a 3D plot to the left bottom corner of the display window, and having enlarged it along the horizontal direction, I get the plot cutoff (but the frame remains) right where the gray border is displayed. Anyone knows how to avoid the cutoff? Here is my script and the resulting plot:

# 3D DELAUNAY TRIANGULATION OF AN UNSTRUCTURED-GRID DATAFILE

import numpy as np
import matplotlib.tri as mtri
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
with open('../gnuplot/bin/datos.txt', 'r') as f:
    lines = f.readlines()

    x, y, z = np.genfromtxt("../gnuplot/bin/datos.txt", unpack=True)

fig = plt.figure()
ax = fig.add_subplot(1,1,1)

ax.scatter(x, y, marker=".", c="#DC143C", edgecolors="black", s=100)
ax.set_xlabel('X')
ax.set_ylabel('Y')

triang = mtri.Triangulation(x, y)

fig = plt.figure()
ax = fig.add_subplot(1,1,1)

ax.triplot(triang, c="#D3D3D3", marker='.', markerfacecolor="#DC143C",
    markeredgecolor="black", markersize=5)

ax.set_xlabel('X')
ax.set_ylabel('Y')

isBad = np.where((x<-1) | (x>7) | (y<12) | (y>88), True, False)

mask = np.any(isBad[triang.triangles],axis=1)
triang.set_mask(mask)

fig = plt.figure()
ax = fig.add_subplot(1,1,1)

ax.triplot(triang, c="#D3D3D3", marker='.', markerfacecolor="#DC143C", 
    markeredgecolor="black", markersize=5)

ax.set_xlabel('X')
ax.set_ylabel('Y')

fig, ax = plt.subplots(subplot_kw={'projection':'3d'}, facecolor='lightgray')
fig.subplots_adjust(bottom=0, left=-0.15, top=1, right=0.56)
ax.get_proj = lambda: np.dot(Axes3D.get_proj(ax), np.diag([2.0, 2.0, 1.0, 1]))
#fig.patch.set_alpha(0.0) THIS JUST CHANGES THE COLOR OF THE BORDER TO WHITE

ax.plot_trisurf(triang, z, cmap='jet')
ax.scatter(x,y,z, marker='.', s=10, c="black", alpha=0.5)
ax.view_init(elev=30, azim=-45)

ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')

# plt.savefig('image.png', bbox_inches='tight', pad_inches=0) THIS DOESN'T WORK

plt.show()

stretched-out 3D plot cutoff in the middle of it

Upvotes: 0

Views: 22

Answers (0)

Related Questions