1

I want to display two figures in one graph, so that they overlapping each other...

here is my code:

ohlc_data = pd.DataFrame(mt.copy_rates_range('EURUSD',
                                        mt.TIMEFRAME_D1,
                                        datetime(2021, 1, 1), 
                                        datetime.now()))

ohlc_data2 = pd.DataFrame(mt.copy_rates_range('EURUSD',
                                        mt.TIMEFRAME_H4,
                                        datetime(2021, 1, 1), 
                                        datetime.now()))

fig = px.line(ohlc_data, x=ohlc_data['time'], y=ohlc_data['close'])
fig2 = px.line(ohlc_data2, x=ohlc_data2['time'], y=ohlc_data2['close'])

how can I plot fig & fig2 in one graph instead of seperate ones?

and here the imports:

import MetaTrader5 as mt
import pandas as pd
import plotly.express as px
from datetime import datetime
  • what is `px` and what is `mt`? are you using matplotlib or another library? –  Mar 04 '22 at 10:11
  • i imported plotly.express as "px" and MetaTrader5 as "mt" –  Mar 04 '22 at 10:12
  • @zookeeper85, please add **all** of the `imports` at the top otherwise users trying to help you have to guess those. Sometimes it is obvious other times not. Here is a guide: https://stackoverflow.com/help/minimal-reproducible-example – D.L Mar 04 '22 at 10:22

1 Answers1

0

You can reuse this example, if two plots share the same x-axis:

import plotly.express as px
import plotly.graph_objects as go

df = px.data.gapminder().query("country=='Canada'")
fig1 = px.line(df, x="year", y="lifeExp", title='Life expectancy in Canada')
fig1.update_traces(line_color='red')

df = px.data.gapminder().query("country=='Australia'")
fig2 = px.line(df, x="year", y="lifeExp", title='Life expectancy in Australia')
fig1.update_traces(line_color='black')

fig3 = go.Figure(data=fig1.data + fig2.data)
fig3.update_xaxes(title_text="Yea")
fig3.update_yaxes(title_text="Life Expenses")

fig3.show()

enter image description here

Hamzah
  • 8,175
  • 3
  • 19
  • 43