简体   繁体   English

同一图中的两个不同图表

[英]Two different graphs in the same plot

I want to plot a wirerframe and a scatter plot in the same plot. 我想在同一个图中绘制一个wirerframe和一个散点图。 Here's what I do: 这是我做的:

from mpl_toolkits.mplot3d import axes3d
import matplotlib.pyplot as plt
import numpy as np

fig = plt.figure()

ax1 = fig.add_subplot(111, projection='3d')
X, Y, Z = axes3d.get_test_data(0.05)
ax1.plot_wireframe(X, Y, Z, rstride=10, cstride=10)

ax2 = fig.add_subplot(111, projection='3d')
xs = np.array( [ 1, 0 ,2 ])
ys = np.array( [ 1, 0, 2 ])
zs = np.array( [ 1, 2, 3 ])
ax2.scatter(xs, ys, zs)

plt.show()

This script just gives the scatter plot. 此脚本仅提供散点图。 Comment any block and you get the uncommented plot. 评论任何块,你会得到未注释的情节。 But they won't go on the same plot together. 但他们不会一起出现在同一个阴谋中。

When you add_subplot(111) again, you override the previous subplot. 再次添加add_subplot(111)时,将覆盖上一个子图。 Just don't do that, and plot on the same axes twice: 只是不要这样做,并在同一轴上绘制两次:

from mpl_toolkits.mplot3d import axes3d
import matplotlib.pyplot as plt
import numpy as np

fig = plt.figure()

ax = fig.add_subplot(111, projection='3d')
X, Y, Z = axes3d.get_test_data(0.05)
ax.plot_wireframe(X, Y, Z, rstride=10, cstride=10)

xs = np.array( [ 1, 0 ,2 ])
ys = np.array( [ 1, 0, 2 ])
zs = np.array( [ 1, 2, 3 ])
ax.scatter(xs, ys, zs)

plt.show()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在python中绘制两个不同的图形 - How to plot two different graphs in python 在 Python 中用不同颜色在同一张图上绘制 n 个不同的图 - Plot n different graphs on the same plot with different colors in Python Pyqtgraph:在同一图形窗口中实时绘制两个相同X轴但两个Y轴相反方向的图形 - Pyqtgraph: plot real time two graphs same X-axis but two different Y-axis in opposite direction in a same graph window Matplotlib:当同一类中的不同函数调用绘图例程时,在同一绘图上绘制多个图吗? - Matplotlib: plot multiple graphs on the same plot when different functions in the same class call the plot routine? 如何在 pandas 中的单个图形上 plot 两个不同的图形? - How to plot two different graphs on a single figure in pandas? Matplotlib:当同一类中的不同函数调用绘图例程时,在同一图形上绘制多个图形作为子图? - Matplotlib: plot multiple graphs as subplots on the same figure when different functions in the same class call the plot routine? Plot 具有相同 y 刻度的 2 个图 - Plot the 2 graphs with same y scale 在seaborn的同一个地块上的多个图表 - Multiple graphs on the same plot in seaborn 为什么matplotlib图形和图标在具有相同操作系统的两台计算机上看起来不同? - Why matplotlib graphs and icons look different on two computers with the same OS? 如何 plot 两个条形图 - how to plot two bar graphs
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM