2

I have a lists that I want to convert to a line chart graph, the results I get are very chaotic, the list contain negative and positive values.

my code:

macd = []
signals = []

for i in data['Technical Analysis: MACD'].values():
    macd.insert(len(macd), i['MACD'])
    signals.insert(len(signals), i['MACD_Signal'])

plt.plot(macd)
plt.plot(signals)
plt.show()

Here what I get: enter image description here

data example:

macd = ['-0.0099', '-0.0108', '-0.0091', '-0.0074', '-0.0052', '-0.0002', '0.0032', '0.0064', '0.0083', '0.0107', '0.0106', '0.0102', '0.0126', '0.0145', '0.0137', '0.0114', '0.0093', '0.0055', '-0.0005', '-0.0070', '-0.0082', '-0.0116', '-0.0137', '-0.0152', '-0.0159', '-0.0175', '-0.0184', '-0.0191', '-0.0199', '-0.0205', '-0.0210', '-0.0214', '-0.0205', '-0.0191', '-0.0170', '-0.0161', '-0.0148', '-0.0118', '-0.0089', '-0.0091', '-0.0082', '-0.0070', '-0.0073', '-0.0076', '-0.0069', '-0.0064', '-0.0062', '-0.0048', '-0.0039', '-0.0028']

signals = ['-0.0042', '-0.0028', '-0.0008', '0.0012', '0.0034', '0.0056', '0.0070', '0.0079', '0.0083', '0.0083', '0.0077', '0.0070', '0.0062', '0.0046', '0.0021', '-0.0008', '-0.0038', '-0.0071', '-0.0102', '-0.0127', '-0.0141', '-0.0156', '-0.0165', '-0.0173', '-0.0178', '-0.0182', '-0.0184', '-0.0184', '-0.0182', '-0.0178', '-0.0172', '-0.0162', '-0.0149', '-0.0135', '-0.0121', '-0.0109', '-0.0096', '-0.0083', '-0.0074', '-0.0070', '-0.0065', '-0.0061', '-0.0059', '-0.0055', '-0.0050', '-0.0045', '-0.0041', '-0.0036', '-0.0033', '-0.0031']
2
  • Can you provide an example of the data? Commented Aug 25, 2021 at 11:03
  • I provided some examples in the question. Commented Aug 25, 2021 at 11:16

1 Answer 1

2

Values in your data are str, you need to convert them in number type like float before plotting:

macd = list(map(float, macd))
signals = list(map(float, signals))

enter image description here

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

2 Comments

Thanks, I really feel stupid for not noticing that.
@AdamDemo_Fighter that's why it is always better to provide a minimal example ;)

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.