0

This question was edited from the original for more clarity.

I have a python code to plot two surfaces. However, they overlap each other in line where I would like to "trim" those surfaces so I could get a perfect edge at their intersection. My code so far is:

import numpy as np
import matplotlib.pyplot as plt
from matplotlib import cm
import time
import pdb
start_time = time.time()

fig = plt.figure(figsize=(8,4))
ax = fig.add_subplot(projection='3d')
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_zlabel('z')    

x = np.linspace(-2.5,3.104,1000)
y = np.linspace(-0.746,0,1000)-1
X, Y = np.meshgrid(x, y)
Z = -1.0716*(Y+1)
solid = ax.plot_surface(X,Y,Z,cmap=cm.coolwarm,linewidth=0, antialiased=True)

y = np.linspace(-1.746,1,1000)
x = np.linspace(0,0.604,1000) + 2.5
X, Y = np.meshgrid(x, y)
Z = 1.323*(X-2.5)
solid = ax.plot_surface(X,Y,Z,cmap=cm.coolwarm,linewidth=0, antialiased=True)

enter image description here

My original plan was to plot those two "corner" regions separately as triangles that I know the vertices, however, it was not clear how could I adopt the same color mapping that I desire since the convenient way to do these triangular regions is to set a limited plane, for example, this question, where the triangle is defined by setting Z[Z<0]=0.

The problem is that I don't know how to set a similar condition to define my triangular region since it depends on a line inside that plane, which is not a constant as in the other question. All the points where the intersections between the planes occur can be calculated, I just don't know how do I set this visualization on Python. Thank you in advance!

  • There are no colors because the shape is only defined by the corners of the triangle. See this [question](https://stackoverflow.com/q/44244297/7758804) and how the data varies. Also see [matplotlib plot_trisurf site:stackoverflow.com](https://www.google.com/search?q=matplotlib+plot_trisurf+site:stackoverflow.com&rlz=1C1ONGR_enUS976US976&sxsrf=AOaemvJqcrQ7sHD72-hr6ZVmXmitdUe4Pw:1637601717898&sa=X&ved=2ahUKEwiky7blvaz0AhUKv54KHWc0A_0QrQIoBHoECAUQBQ&biw=1278&bih=1327&dpr=1) – Trenton McKinney Nov 22 '21 at 17:27
  • 1
    Does this answer your question? [How to fill a 3D triangle with a color gradient](https://stackoverflow.com/q/42213466/77588040) – Trenton McKinney Nov 22 '21 at 17:33
  • Thank you @TrentonMcKinney, I understand why it has a single color, my question is on how could I proceed to make it be made of more regions, so I could plot with the desired effect. I believe that I need to interpolate the data to create more points, but it's not clear how can I make with this. EDIT: I'll take a look on the last link. – Mateus Forcelini Nov 22 '21 at 17:37
  • The answer in the immediately preceding comment uses `meshgrid` and a mask to define the triangle. `meshgrid` will be an array with many points. – Trenton McKinney Nov 22 '21 at 17:39

0 Answers0