我有一个代码,我根据变量的值绘制一些箭头,但有时这些值很大,如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()
我只是为您准备了所有代码,以确定我必须更改比例以使其记录的位置。
谢谢!
答案 0 :(得分:2)
使用轴方法set_xscale
或set_yscale
。
ax.set_xscale('log')
答案 1 :(得分:0)
我有同样的问题。这似乎是至少2011年与使用对数刻度轴的曲面绘图相关的错误。邮件列表线程表明除了对数据进行日志缩放和线性绘制之外,没有简单的解决方法。
https://www.mail-archive.com/matplotlib-users@lists.sourceforge.net/msg22832.html