0

I have a line graph which I have done with matplotlib from this dataframe called lineFGDF:

enter image description here

The code I used is:

fig, ax2 = plt.subplots(figsize=(15, 10))
x = lineFDF[threeYr]
x.plot(kind='line', marker='',color='#0c1e3c')
plt.grid(color='#e5e0e0', linestyle=':', linewidth=0.8)

It produces this:

enter image description here

Which is great and I can see the Months on the X axis. However, I want to do it with Plotly so I can make it interactive.

So I found a way of doing it in Plotly, but the months have gone and have been replaced with numbers. How do I get the month labels back?

This is the code:

random_x = lineFDF[threeYr]
trace0 = go.Scatter(
    y = random_x,
    mode = 'lines',
    name = 'lines'
)
data = [trace0]
plotly.offline.iplot(data, filename='line-mode')

Which produces this:

enter image description here

1 Answer 1

2

Specify X in your trace0. Set X to be equal to the the months you would like to see.

trace0 = go.Scatter(
    x = ['jan','feb','ma','ap','may','jun'],
    y = [1,2,3,4,5,6],
    mode = 'lines',
    name = 'lines'
)

results in this graph.

enter image description here

Sign up to request clarification or add additional context in comments.

1 Comment

Works perfectly. Thank you! :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.