Python 情节轴在子地块之间的行为非常奇怪。发生了什么事以及如何修复?
下面是一个显示Plotly graph问题的示例 首先请注意,顶部两个正弦函数图的y轴位于圆形极坐标图的左侧。还要注意,它们都没有任何明显的x轴 还请注意,底部的两个图形共享一个x轴(以一种非常奇怪的方式--尝试使用它在图形上左右滑动) 我试着给他们更多的空间。我确信这不是问题所在。地物的轴都已正确定位。老实说,我一点也不知道为什么会把这些事情搞混,任何帮助或反馈都将不胜感激 还要注意的是,轨迹Python 情节轴在子地块之间的行为非常奇怪。发生了什么事以及如何修复?,python,python-3.x,plotly,Python,Python 3.x,Plotly,下面是一个显示Plotly graph问题的示例 首先请注意,顶部两个正弦函数图的y轴位于圆形极坐标图的左侧。还要注意,它们都没有任何明显的x轴 还请注意,底部的两个图形共享一个x轴(以一种非常奇怪的方式--尝试使用它在图形上左右滑动) 我试着给他们更多的空间。我确信这不是问题所在。地物的轴都已正确定位。老实说,我一点也不知道为什么会把这些事情搞混,任何帮助或反馈都将不胜感激 还要注意的是,轨迹l4和l5都要绘制在同一组轴上。这不是一个错误 这是我的密码: from plotly import
l4
和l5
都要绘制在同一组轴上。这不是一个错误
这是我的密码:
from plotly import tools
import plotly.offline as py
import plotly.graph_objs as go
py.init_notebook_mode()
import numpy as np
pi = np.pi
# Define our frequencies
f1, f2 = 2, 6
# generate wave function and data
T = np.linspace(0, 2 * pi, 44100)
def wav(f, t): return np.sin(np.dot(f, t))
def r(t): return wav(f1, t) - wav(f2, t)
# Plot each of the subplots
l0 = go.Scatterpolar(
r=r(T), theta=np.linspace(0, 360, 44100),
name="Rosette Trace")
l1 = go.Scatter(x=T, y=r(T), xaxis="x1", yaxis="y1", name="Perceived Wave")
l2 = go.Scatter(x=T, y=wav(f1, T), xaxis="x2", yaxis="y2", name="Wave 1")
l3 = go.Scatter(x=T, y=wav(f2, T), xaxis="x3", yaxis="y3", name="Wave 2")
l4 = go.Scatter(x=T, y=wav(f1, T), xaxis="x4", yaxis="y4", name="Waves_12")
l5 = go.Scatter(x=T, y=wav(f2, T), xaxis="x4", yaxis="y4", name="waves_12")
# Which subplots will be plotted
data = [l0, l1, l2, l3, l4, l5]
layout = go.Layout(
# Set position and layout of Polar graph
# 'domain' controls position and relative size of subplots
polar=dict(
domain=dict(x=[0.0, 0.35], y=[0.5, 1]),
angularaxis=dict(thetaunit="radians"),
radialaxis=dict(range=[-2, 2.1])),
# Set positions and layouts of wave function graphs
# 'domain' controls position and relative size of subplots
xaxis1=dict(anchor="x1", domain=[0, 1]),
yaxis1=dict(anchor="y1", domain=[0.25, 0.45]),
xaxis2=dict(anchor="x2", domain=[0.5, 1]),
yaxis2=dict(anchor="y2", domain=[0.8, 1]),
xaxis3=dict(anchor="x3", domain=[0.5, 1]),
yaxis3=dict(anchor="y3", domain=[0.55, 0.75]),
xaxis4=dict(anchor="x4", domain=[0, 1]),
yaxis4=dict(anchor="y4", domain=[0, 0.2]),
# Set layout options for entire figure
margin=dict(r=40, t=45, b=40, l=60),
title='Fancy Title',
height=625,
showlegend=False
)
# Define a variable containing the entire figure of plots
fig = go.Figure(data=data, layout=layout)
# Make it happen!
py.iplot(fig)
为了回答我自己的问题,我发现锚定属性需要以不同的方式使用,例如yaxis1锚定到x1,xaxis1锚定到y1:
# Plot each of the subplots
l0 = go.Scatterpolar( # converts radians to degrees, but can
r=r(T), theta=T*(360/(2*np.pi))) # also use np.linspace(0, 360, 44100))
l1 = go.Scatter(x=T, y=r(T), xaxis="x1", yaxis="y1", name="Perceived Wave")
l2 = go.Scatter(x=T, y=wav(f1, T), xaxis="x2", yaxis="y2", name="Wave 1")
l3 = go.Scatter(x=T, y=wav(f2, T), xaxis="x3", yaxis="y3", name="Wave 2")
l4 = go.Scatter(x=T, y=wav(f1, T), xaxis="x4", yaxis="y4", name="Waves_12")
l5 = go.Scatter(x=T, y=wav(f2, T), xaxis="x4", yaxis="y4", name="waves_12")
这就解决了问题