0

enter image description here

Any explication why I got this kind of plot? The range of index returns is from 100 to 130. I need help to understand this plot above. The code is simple, but the plot is unclear:

#import needed library
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd

#import JPM GBI bound index
df = pd.read_excel('art.xlsx')
df = pd.DataFrame(df) 
df.head(8)

plt.plot(df\['Date'\],df\['Index returns'\])
type(df\['Date'\]\[3\])
5
  • Can you clarify what you mean by "unclear"? We don't know anything about the source data for that plot Commented May 22, 2018 at 8:45
  • Welcome to SO. I took the liberty to reformat your question a little. Specifically I removed something that did not look like valid Python code, but like a broken link to an image from your code. Can you please verify that everything is still in order? Additionally: What exactly do you expect to happen? What kind of plot would you expect? Commented May 22, 2018 at 9:14
  • 1
    It looks like the axis should be the other way round. Commented May 22, 2018 at 9:19
  • I think dzejdzej is right. Try to revert y and x axis and see what happens. Commented May 22, 2018 at 9:48
  • i don't think that there is an issue in the data cuz i have Index returns from 100,98,...,130 even when i chnaged the axis nothing changed Commented May 22, 2018 at 10:39

1 Answer 1

1

Matplotlib plots the data in the order it is provided. You may sort the data if that is required.

import numpy as np
import matplotlib.pyplot as plt

x = np.array([3, 5, 1, 2, 7, 4, 6, 9, 8])
y = np.array([8, 10, 3, 6, 8, 10, 10, 3, 6])

plt.subplot(121)
plt.plot(x,y, marker="o", label="unsorted")

plt.legend()

# now sort the values
plt.subplot(122)
plt.plot(np.sort(x),y[np.argsort(x)], marker="o", color="C3", label="sorted")

plt.legend()
plt.show()

enter image description here

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

1 Comment

Thanks for your clarification it helps

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.