0

,,,

    print (data)
    close_prices = data[1]
    dates = data.index 

    fig, ax = plt.subplots()
    ax.plot(dates, close_prices)
    ax.set_xticklabels(dates, rotation=45)
    ax.set_title(f"Daily Close Prices for IBM")
    ax.set_xlabel("Date")
    ax.set_ylabel("Price ($)")

    plt.tight_layout()
    plt.show()

,,,

The data is called from the AlphVantage api and I am outputting it in a pandas format. How do I get only the Close price to be plotted on the graph? enter image description here

Cruel
  • 11
  • 2
  • 2
    is the data a DataFrame or stuck in tuples inside it somehow? DataFrames can be directly selected down to the column(s) you're after `df[["date", "4. close"]]` – ti7 Jun 28 '23 at 04:46
  • Difficult to answer without a reproducible example (an image is not reproducible). Maybe `close_prices = data[1]["4. close"]`. – mozway Jun 28 '23 at 05:13
  • @ti7 the values are stuck inside tuples. I tried running the code you listed but it gave an error saying tuple indices must be integers or slices not list. – Cruel Jun 28 '23 at 06:17
  • @mozway here's an [image of the error.](https://files.catbox.moe/1mzi4z.png) – Cruel Jun 28 '23 at 06:20
  • 1
    @Cruel that's not what I suggested and please read [how to ask](https://stackoverflow.com/help/how-to-ask) and [how to make good reproducible pandas examples](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) – mozway Jun 28 '23 at 06:56
  • @mozway alright I will and keep that in mind when I make future posts. Can I ask what you meant then? – Cruel Jun 28 '23 at 08:22
  • 3
    Why don't you [edit] your current question to provide reproducible data? – mozway Jun 28 '23 at 08:26

1 Answers1

-2
import pandas as pd
import matplotlib.pyplot as plt

data = [(1, 3), (2, 5), (3, 4), (4, 6), (5, 8)]
df = pd.DataFrame(data, columns=['x', 'y'])

df.plot(x='x', y='y', kind='line')
plt.show()
Shiran Yuan
  • 105
  • 5
Rk dev tech
  • 190
  • 1
  • 14