Note that there are some explanatory texts on larger screens.

plurals
  1. POdrawing a line on a 3D plot in matplotlib
    text
    copied!<p>I have a 3D plot which looks quite similar to <a href="https://stackoverflow.com/questions/10917495/matplotlib-imshow-in-3d-plot">this one</a> , but I want to add two lines drawn on the bottom contour plot. I would like the two lines to cross at and point to a particular (x,y) value.</p> <p>I can draw a line there but it is always beneath the contour plot, despite my numerous attempts. Can anyone help me drawing the line <em>on</em> the contour plot? I am pasting my code below. The line is visible only in the part where it sticks out from the contour.</p> <pre><code>#!/usr/bin/env python import sys, re, math import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D from matplotlib.collections import LineCollection from matplotlib import cm from matplotlib.mlab import griddata import numpy as np x = [] y = [] z = [] for i in range(0,628,10) : for j in range(0,628,10) : x.append(i*0.01) y.append(j*0.01) z.append(math.sin(x[-1]*y[-1])*20) fig = plt.figure() ax = fig.gca(projection='3d') xi = np.linspace(min(x), max(x)) yi = np.linspace(min(y), max(y)) X, Y = np.meshgrid(xi, yi) Z = griddata(x, y, z, xi, yi) ax.autoscale(False) ax.view_init(elev=30, azim=-140) surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.cool, linewidth=0.1, antialiased=True, shade=True,alpha=0.8) cset = ax.contourf(X, Y, Z, zdir='z', offset=-100, cmap=cm.cool, cstride=1, linewidth=0.1, antialiased=True, shade=True) ax.set_xlim3d(0, math.pi*2) ax.set_ylim3d(0, math.pi*2) ax.set_zlim3d(-100, 20) xi = [0,6] yi = [3,3] l=zip(xi,yi) lines = LineCollection((l,l),zorder=10000,color='k') ax.add_collection3d(lines,zs=-90) plt.show() </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload