Ich versuche ein Plotly-Diagramm mit Scatter- und Graph-Elementen zu erstellen. Es geht alles gut, aber ein Problem - die zwei Y-Achse nicht um 0.Python Plotly - Y-Achse für Scatter und Bar ausrichten
Ich habe versucht zu spielen mit verschiedenen Attributen, wie "Spiegel" und Tick0, ich habe auch versucht, die Beispiele auf Plotly Website folgen, aber es ist meistens mehrere Y-Achsen mit dem gleichen Graphen-Typ.
Was kann ich tun, um das Problem zu beheben?
import utils
import pandas as pd
import plotly.plotly as py
import plotly.graph_objs as go
import plotly
pd_data ['dt'] = ... dates
pd_data['price'] = ... prices
pd_data['car'] = ... cars
price = go.Scatter(
x = pd_data['dt'],
y = pd_data['price'],
mode = 'lines',
name = 'Price',
xaxis = 'x',
yaxis='y1',
marker = dict(
color = utils.prep_color_string('orange'),
),
line = dict(
width = utils.line_width,
),
)
car = go.Bar(
x = pd_data['dt'],
y = pd_data['car'],
#mode = 'lines',
name = 'Cars',
xaxis = 'x',
yaxis='y2',
marker = dict(
color = utils.prep_color_string('light_green'),
),
#line = dict(
# width = utils.line_width,
#),
)
data = [price, car]
layout = dict(
title = 'Price/Car',
geo = dict(
showframe = True,
showcoastlines = True,
projection = dict(
type = 'Mercator'
)
),
yaxis=dict(
title = 'Price',
tickprefix = "$",
overlaying='y2',
anchor = 'x'
),
yaxis2=dict(
title = 'Car',
dtick = 1,
#tickprefix = "",
side = 'right',
anchor = 'x',
),
)
fig = dict(data=data, layout=layout)
div = plotly.offline.plot(fig, validate=False, output_type = 'file',filename='graph.html' ,auto_open = False)
Wenn Sie einen MCVE bereitstellen können, erhalten Sie schneller eine gute Antwort. http://StackOverflow.com/Help/Mcve – steven