1

So I am trying to plot 3 dimensionally with matplotlib.pyplot, but only in a specific domain whose boundary is set by a function. Here is the code

import numpy
from scipy.integrate import quad
import matplotlib.pyplot
import matplotlib.ticker
from mpl_toolkits.mplot3d import Axes3D

def get_x1min(pT, eta, rS):
    return (pT * numpy.exp(eta)) / (rS - pT * numpy.exp(- eta))

def get_x2(x1, pT, eta, rS):
    return (x1 * pT * numpy.exp(- eta)) / (x1 * rS - pT * numpy.exp(eta))

rS = 1960.0
eta = 0.0
pT = [66.0, 77.5, 89.5, 92.0, 94.0, 96.0, 98.0, 100.0, 103.0, 105.0, 107.0, 109.0, 111.0, 113.0, 118.5, 136.5, 157.5, 182.0, 200.0, 209.5, 241.5, 278.5, 321.0, 370.0, 426.5, 492.0]

fig = matplotlib.pyplot.figure()
ax = Axes3D(fig)
x1_test = numpy.linspace(0.1, 1.0, 20)
x1_test, pT = numpy.meshgrid(x1_test, pT)
x2_test = get_x2(x1_test, pT, eta, rS)
ax.plot_surface(x1_test, pT, x2_test, rstride=1, cstride=1, cmap=matplotlib.pyplot.get_cmap('rainbow'))
matplotlib.pyplot.show()

This works fine BUT the domain is a rectangle, and the only change needed is to have x1_test just start from a minimum that can be obtained from function get_x1min. Is there any method of doing it?

Thanks in advance!

0

1 Answer 1

3

You can set the unwanted values to np.nan, then they will not be plotted. Note though that there seems to be some problems with the colormapping. You can get around this using the vmin and vmax keywords:

mask = x1_test< get_x1min(pT, eta, rS)
x2_test[mask] = numpy.nan

ax.plot_surface(
    x1_test, pT, x2_test, rstride=1, cstride=1,
    cmap=matplotlib.pyplot.get_cmap('rainbow'),
    vmin = numpy.nanmin(x2_test),
    vmax = numpy.nanmax(x2_test),    
    )

matplotlib.pyplot.show()

The rest of the code would stay the same. The result looks something like this:

result of the OP's code patched with the code posted above

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.