I would like to mark max/min value as yticks like below:
import plotly.graph_objects as go
import pandas as pd
import plotly.express as px
def save_fig(fig,pngname):
fig.write_image(pngname,format="png",width=800,height=500, scale=1)
print("[[%s]]"%pngname)
#fig.show()
return
DATE='Date'
VAL='AAPL.High'
url='https://raw.githubusercontent.com/plotly/datasets/master/finance-charts-apple.csv'
def main():
df = pd.read_csv(url)
fig = px.line(df, x=DATE, y=VAL)
for val in [df[VAL].min(),df[VAL].max()]:
fig.add_hline(
y=val,
annotation_text=f"{val:.2f}",
line_width=.5,line_color='grey',
annotation_position="left")
print(df[VAL].min())
save_fig(fig,"/media/sf_work/demo.png")
return
main()
`
But current solution the min/max ticks will overlap. how can I replace start and end ticks with the min,max value instead of add a new one to avoid such overlap? Maybe read current ticks array then replace first and last value but not sure how to do it.
2