0

我有一个代码,我根据变量的值绘制了一些箭头,但有时这些值很大,例如 9000,有时值较小,例如 400。那么我怎样才能以对数形式对图表进行刻度坐标轴比例根据箭头的值而变化。

from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np
from itertools import product, combinations, cycle
from numpy import sin, cos
from matplotlib.patches import Rectangle, Circle, PathPatch
import mpl_toolkits.mplot3d.art3d as art3d
import wave
import sys
import matplotlib as mpl


fig = plt.figure()
ax = fig.gca(projection='3d')
ax.set_aspect("auto")
ax.set_autoscale_on(True)

font = {'family' : 'broadway',
        'color'  : 'blue',
        'weight' : 'normal',
        'size'   : 16,
        'horizontalalignment': 'right',
        }

#dibujar cubo
r = [-10000, 10000]
for s, e in combinations(np.array(list(product(r,r,r))), 2):
    if np.sum(np.abs(s-e)) == r[1]-r[0]:
        ax.plot3D(*zip(s,e), color="b")

#dibujar punto
ax.scatter([0],[0],[0],color="g",s=100)

#dibujar vector
from matplotlib.patches import FancyArrowPatch
from mpl_toolkits.mplot3d import proj3d

class Arrow3D(FancyArrowPatch):
    def __init__(self, xs, ys, zs, *args, **kwargs):
        FancyArrowPatch.__init__(self, (0,0), (0,0), *args, **kwargs)
        self._verts3d = xs, ys, zs

    def draw(self, renderer):
        xs3d, ys3d, zs3d = self._verts3d
        xs, ys, zs = proj3d.proj_transform(xs3d, ys3d, zs3d, renderer.M)
        self.set_positions((xs[0],ys[0]),(xs[1],ys[1]))
        FancyArrowPatch.draw(self, renderer)
#print "ingrese coordenada inicial: "

a1 = 120
b1 = -410
c1 = 200
d1 = -652
e1 = 800
f1 = -500

a1=0.3
b1=-1
c1=0.5
d1=-0.6
e1=0.2
f1=-0.4

a = Arrow3D([0,0],[0,a1],[0,0], mutation_scale=20, lw=1, arrowstyle="-|>", color="k")
b = Arrow3D([0,b1],[0,0],[0,0], mutation_scale=20, lw=1, arrowstyle="-|>", color="r")
c = Arrow3D([0,0],[0,0],[0,c1], mutation_scale=20, lw=1, arrowstyle="-|>", color="b")
d = Arrow3D([0,0],[0,0],[0,d1], mutation_scale=20, lw=1, arrowstyle="-|>", color="g")
e = Arrow3D([0,e1],[0,0],[0,0], mutation_scale=20, lw=1, arrowstyle="-|>", color="c")
f = Arrow3D([0,0],[0,f1],[0,0], mutation_scale=20, lw=1, arrowstyle="-|>", color="m")

ax.add_artist(a)
ax.add_artist(b)
ax.add_artist(c)
ax.add_artist(d)
ax.add_artist(e)
ax.add_artist(f)

ax.set_xlabel("Amplitud en X", size  = 18, color = 'r', family =  'verdana')
ax.set_ylabel("Amplitud en Y", size  = 18, color = 'r', family =  'verdana')
ax.set_zlabel("Amplitud en Z", size  = 18, color = 'r', family =  'verdana')
ax.text2D(0.05, 0.95, "Intensimetro de Audio", fontsize=16, transform=ax.transAxes)
#plt.title('Intensimetro de Audio',fontdict=font)

lista = [a1,f1]
list.sort(lista, key=abs, reverse=True)
print lista

lista1 = [b1,e1]
list.sort(lista1, key=abs, reverse=True)
print lista1

lista2 = [c1,d1]
list.sort(lista2, key=abs, reverse=True)
print lista2

if abs(b1)>abs(e1):
    h=b1
else:
    h=e1
if abs(a1)>abs(f1):
    j=a1
else:
    j=f1
if abs(c1)>abs(d1):
    k=c1
else:
    k=d1

a = [0, 0, 0]
b = [h, j, k]
xs,ys,zs = zip(a,b)
print (xs,ys,zs)

res = Arrow3D(xs, ys, zs, mutation_scale=20, lw=1, arrowstyle="simple", color='y')
ax.add_artist(res)

plt.show()

我放了所有代码只是为了让您确定我必须在哪里更改比例以使其记录。

谢谢!

4

2 回答 2

2

使用 Axis 方法set_xscaleset_yscale.

ax.set_xscale('log')
于 2013-10-31T22:28:09.087 回答
0

我有同样的问题。这似乎是至少 2011 年的一个错误,与使用对数刻度轴的表面绘图有关。邮件列表线程表明,除了对数据进行对数缩放和线性绘制之外,没有简单的解决方法。

https://www.mail-archive.com/matplotlib-users@lists.sourceforge.net/msg22832.html

于 2013-12-10T05:47:20.843 回答