【发布时间】:2017-05-26 22:12:09
【问题描述】:
(对 python 非常陌生)所以我制作了一个 3D 散点图,我想在其中添加不同“类型”的点。目前我想将值附加到 X1、Y1、Z1 以创建有问题的点。如果我手动输入这些,似乎没有任何问题。但是,当我尝试在课堂外使用 append 函数时,这些点不会显示在我的绘图上。我希望能够在我的散点图上从外部附加或添加点。
import numpy as np
import math
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
font = {'fontname': 'Franklin Gothic Demi'}
title = {'fontname': 'Bookman Old Style'}
diameter = 3500
width = 200
class world(object):
def __init__(self):
self.fig = plt.figure()
self.fig.add_subplot(111, projection="3d")
self.ax = plt.gca()
self.t = 0
self.X1 = []
self.Y1 = []
self.Z1 = []
self.ax.scatter(self.X1, self.Y1, self.Z1, c="r", marker="1", depthshade=True)
self.ax.set_xlabel("synaptic diameter (nm)", color = "navy", **font)
self.ax.set_ylabel("synaptic diameter (nm)", color = "navy", **font)
self.ax.set_zlabel("cleft width (nm)", color = "navy", **font)
self.ax.autoscale(enable=True)
self.ax.set_xlim(0, diameter)
self.ax.set_ylim(0, diameter)
self.ax.set_zlim(0, width)
plt.gca().invert_xaxis()
plt.title("Synapse", color = "black", size = 20, **title)
self.Serotonin = []
self.MAO = []
self.immobileAgents = []
#not yet relevant here
def showPlot(self):
self.showPlot = plt.show()
这是我用来将值附加到列表的(其中一个)函数
world = world()
tee = 0
while tee <= 100:
world.X1.append(tee)
world.Y1.append(tee)
world.Z1.append(tee)
tee = tee + 1
print (world.X1)
print (world.Y1)
print (world.Z1)
#just to be sure
world.showPlot()
请注意,在这种情况下,目的仅仅是为了能够看到我的情节上的点。他们的位置根本不重要。
【问题讨论】: