Introduction to Line Plot Graphs with matplotlib Python

แชร์
ฝัง
  • เผยแพร่เมื่อ 4 ต.ค. 2024

ความคิดเห็น • 81

  • @새벽별-t1t
    @새벽별-t1t ปีที่แล้ว +2

    # Yahoo Finance data download method has changed.
    # pip install yfinance
    # After installing yfinance
    import pandas as pd
    import yfinance as yf
    import matplotlib.pyplot as plt
    start_date='2019-01-01'
    end_date='2023-01-06'
    data = yf.download('AAPL', start_date, end_date)
    # data.head()
    # plt.plot(data['Close'])
    plt.plot(data.Close)
    # Anyway, it was helpful. Thank you.

    • @MattMacarty
      @MattMacarty  ปีที่แล้ว +2

      Yes, yfinance is actually a different module which is an alternative to the pandas_datareader.

    • @Hassan_MM.
      @Hassan_MM. 8 หลายเดือนก่อน

      ❤❤ Thanks ya all

  • @lausatomi5675
    @lausatomi5675 4 ปีที่แล้ว +4

    Your explanation is very clear. You are a great teacher! Thank you so much ^^

    • @MattMacarty
      @MattMacarty  4 ปีที่แล้ว

      Thank you. Glad it helped.

  • @danielchacreton2401
    @danielchacreton2401 4 ปีที่แล้ว +4

    This perfect. Short and sweet. Thanks for taking the time to make this.

    • @MattMacarty
      @MattMacarty  4 ปีที่แล้ว

      Thanks. Glad it helped.

  • @faisalali.18
    @faisalali.18 3 ปีที่แล้ว +1

    Just got what I was looking for. Thanks for explaining it perfectly!

  • @TehBr0
    @TehBr0 11 วันที่ผ่านมา

    Excellent intro, this really helped, thank you.

    • @MattMacarty
      @MattMacarty  9 วันที่ผ่านมา

      Thanks. Glad it helped

  • @lucho290197
    @lucho290197 3 ปีที่แล้ว

    Perfect introduction!! Just what i needed. Thank you!

  • @ravindukarunarathne507
    @ravindukarunarathne507 2 ปีที่แล้ว

    Very clear and concise.

  • @AlanGregorySEO
    @AlanGregorySEO 3 ปีที่แล้ว

    I didn't get the answer I needed but this was excellent and I learned a lot of new things - thanks

    • @MattMacarty
      @MattMacarty  3 ปีที่แล้ว +1

      Thanks. Glad it helped, but what were you looking for?

    • @AlanGregorySEO
      @AlanGregorySEO 3 ปีที่แล้ว

      @@MattMacarty hey Matt, I have a set of daily weather data for a whole year. I need to plot (Mean Humidity - for example) - but only for Spring
      So plot a specific column of data between a specific set of dates?
      Can't find the answer anywhere ha ha also I'm a total newbie

  • @titotito1128
    @titotito1128 ปีที่แล้ว

    this is clear , thank you so much...

  • @rahmatsigit957
    @rahmatsigit957 2 ปีที่แล้ว

    very helpfull for my end semester task, terimakasih sir!

  • @movyacreates6474
    @movyacreates6474 ปีที่แล้ว

    It saved my day🤗
    I can't thank you enough🥺

  • @herbrabe6865
    @herbrabe6865 3 ปีที่แล้ว

    This is nice and simple but informative

  • @keiserious
    @keiserious 3 ปีที่แล้ว

    This is so good, short and easy to understand, 🤟

    • @MattMacarty
      @MattMacarty  3 ปีที่แล้ว

      Thanks. Glad it helped

  • @visualizersmusic
    @visualizersmusic 3 ปีที่แล้ว +1

    Really informative! Thx!

    • @MattMacarty
      @MattMacarty  3 ปีที่แล้ว

      Glad it was helpful!

  • @prachigupta9194
    @prachigupta9194 4 ปีที่แล้ว +1

    Thank You for this useful video :)

  • @skynetpro549
    @skynetpro549 2 ปีที่แล้ว

    best video ever !!

  • @paulatkins9240
    @paulatkins9240 ปีที่แล้ว

    Hi Matt awesome videos. I'm trying to use python to plot support and resistance lines on an alpaca paper trading account. Have you done a video on this? thanks!

    • @MattMacarty
      @MattMacarty  ปีที่แล้ว

      Hi no I haven't. You want support and resistance relative to what?

    • @paulatkins9240
      @paulatkins9240 ปีที่แล้ว

      @@MattMacarty ok so i am subscribed to get these daily market insights. I have made a scraper using python to just extract the ticker, resistance & support levels from it each day. I have been manually charting the R&S levels, buying at resistance breakouts with a 2% stop loss. If the stock increases by 10% I sell with a limit order with 5% trailing stop. It's been working really well but i want to take it to the next level with automation and back testing. I'm going to scrape from all the previous 2 years of daily insights, the dates, tickers, resistance and support levels into a csv. I then want to backtest my strategy on all the previous insights. Be able to adjust the strategy to compare returns then automate buying and selling using alpaca with python. Thats when I found your channel!

  • @gilltim5711
    @gilltim5711 4 ปีที่แล้ว

    Hi, Matt. Thank you for posting this. As you may know, this was made before Yahoo discontinued their access to stock data. Could you please make a video explaining how we can use the above graphing information if we pick up the data manually by downloading a CSV file from Yahoo, with the high, low and close, then importing it into Python? And how about a high, low, close graph for a stock? How do we create that? Great job, however.

    • @MattMacarty
      @MattMacarty  4 ปีที่แล้ว

      HI. If you import pandas, pandas.read_csv(path_to_csv) will get your data into a dataframe. You can still get data from Yahoo, but you may have to update/install pandas_datareader. Alternatively there is the yfinance module, or a number of other APIs for pandas_datareader

    • @gilltim5711
      @gilltim5711 4 ปีที่แล้ว

      @@MattMacarty Thanks, Matt. Yes, I've been tinkering with the manual import and figuring out how to combine then call the various columns. It's been a challenge trying to get the Legend to show, but I've figured that out.
      Thank you for these two videos, as every other source went into these complicated pages of code that were needlessly complex and impossible for me to understand. Yours, on the other hand, are direct, to the point, easy to grasp, and usable. As Einstein said, you don't really understand something unless you can explain it to your grandmother! And you clearly understand this material. Great job!

    • @MattMacarty
      @MattMacarty  4 ปีที่แล้ว

      @@gilltim5711 Thanks. I missed your second question though, matplotlib has a separate finance module. This link should get you going in a couple of minutes: github.com/matplotlib/mplfinance
      Plotly also has some financial plotting capabilities.

    • @gilltim5711
      @gilltim5711 4 ปีที่แล้ว

      @@MattMacarty Fantastic! Just what I was looking for! Thank you, Matt.

  • @dogastus
    @dogastus 3 ปีที่แล้ว

    Very useful, thanks.

    • @MattMacarty
      @MattMacarty  3 ปีที่แล้ว

      Glad it was helpful!

  • @sridhardubasi5088
    @sridhardubasi5088 3 ปีที่แล้ว

    nice flow of explanation, can you show me how to swap the axes ?

    • @MattMacarty
      @MattMacarty  3 ปีที่แล้ว +1

      Thanks. You mean you want the lines to down to up instead of left to right?

    • @sridhardubasi5088
      @sridhardubasi5088 3 ปีที่แล้ว

      @@MattMacarty I need labels on X-axis and Y-axis are interchanged..

    • @sridhardubasi5088
      @sridhardubasi5088 3 ปีที่แล้ว

      Yes Matt, that's what I want you to show.. thanks.. 😍
      Can you Show me those lines to down to up instead of left to right..?

  • @sujathayadala6783
    @sujathayadala6783 2 ปีที่แล้ว

    Sir, I have both negative and positive values on my line plots. I want to identify the negative peaks in my plots, then how can I do that. Please help me.

    • @MattMacarty
      @MattMacarty  2 ปีที่แล้ว

      Have you tried the min method in pandas?

  • @tuxcella725
    @tuxcella725 2 ปีที่แล้ว

    Hey, great tutorial. I'm a newbie and I'm trying an extra step but I'm not finding anything on it. Let's say I have the same example as you with two stocks, but instead of showing absolute values, I want to show their variation as percentages (starting from 0). Any easy way to do that with the library or should I convert everything to fit my needs?

    • @MattMacarty
      @MattMacarty  2 ปีที่แล้ว

      Yes there are a number of ways to calculate percent change from some beginning date. One way would be to divide each value in your dataframe by the first value and then subtract 1. Something like this, depending on how you have named things: data['Change'] = data['Close'] / data['Close'].iloc[0] -1

  • @1UniverseGames
    @1UniverseGames 3 ปีที่แล้ว

    On that line graph, how can we use logo at the end of this line. Suppose if we want to use Facebook and Twitter logo, small size or even how can make a circle and write"FB" or Twitter like this at the end of each multiple line.

    • @MattMacarty
      @MattMacarty  3 ปีที่แล้ว

      Take a look at this: th-cam.com/video/FvW3M6MLMoo/w-d-xo.html. I cover annotations here, but not using images. You can use images too, also part of matplotlib with a method strangely called get_sample_data

  • @bishopwashington7964
    @bishopwashington7964 3 ปีที่แล้ว

    good video but I had a question; Amazon and Google have similar trading prices (in the 1000's) what if I am comparing Amazon to Twitter (trades at 30-40) is there a way to change the y axis so it's in more respective terms or in % change per day?

    • @MattMacarty
      @MattMacarty  3 ปีที่แล้ว

      One way would be by taking the log of price. You could also plot them on separate y axes with AMZN on one side of the scale and FB on the other.

  • @margaretgonzalez7248
    @margaretgonzalez7248 3 ปีที่แล้ว

    Could you tell me how I can ask it to plot from a certain date to another? Btw thanks for the great video

    • @MattMacarty
      @MattMacarty  3 ปีที่แล้ว

      Probably the easiest way will be to create a view of your dataframe. You can slice the index column (if that's where the data is) using > and

  • @MrMMF94
    @MrMMF94 ปีที่แล้ว

    If you try it like this you run into an error,
    since pandareader has been updated to yfinance,
    so instead of
    import pandas_datareader as pdr
    you need to import
    importa yfinance as yf
    and instead of
    data = pdr.get_data_yahoo(....)
    you type
    data =yf.download(...)
    That fixed it for me as of 13.5.2023

    • @MattMacarty
      @MattMacarty  ปีที่แล้ว +1

      pandas-datareader is much more comprehensive than yfinance. The problem with data reader is that it needs an update to deal with some API changes on Yahoo finance, so yes use yfinance for now

  • @sarthak2579
    @sarthak2579 4 ปีที่แล้ว

    Hi Matt. Thanks for this useful video!
    Could you tell me how to eliminate the gaps on the left and right hand side of the graph? I want my lines in the graph to start from the tip of the y-axis (whatever their intercept) and end where the graph restricts on the right. Thanks

    • @MattMacarty
      @MattMacarty  4 ปีที่แล้ว +1

      You should be able to make it graph to the edges by setting plt,xlim(min, max)

  • @jackbrents319
    @jackbrents319 3 ปีที่แล้ว

    thank you

  • @julioferreira7500
    @julioferreira7500 4 ปีที่แล้ว

    Great! how can I put the lasts values (for the two stocks) in the grafic? thanks!

    • @MattMacarty
      @MattMacarty  4 ปีที่แล้ว +1

      I show one way of doing this with callouts in this video around the 7:00 mark :th-cam.com/video/FvW3M6MLMoo/w-d-xo.html

  • @christoffere425
    @christoffere425 4 ปีที่แล้ว

    Can you plot for example the Closing price and the Volume in the same graph?

    • @MattMacarty
      @MattMacarty  4 ปีที่แล้ว

      Yes you can do that. It may be much simpler to accomplish with subplots rather than in the same chart though.

    • @christoffere425
      @christoffere425 4 ปีที่แล้ว

      @@MattMacarty Thank you, I did separate plots for them. One more question: how would I best visualize and calculate the correlation between two stocks?

  • @klavenqt
    @klavenqt 2 ปีที่แล้ว

    Could you do this on big data?

    • @MattMacarty
      @MattMacarty  2 ปีที่แล้ว

      You can but you probably want to limit the output to a small window of observations. matplotlib will struggle with large datasets

  • @electronikmale
    @electronikmale 4 ปีที่แล้ว

    Hi,
    if my data is coming from a csv or an excel file and I need to show/copy these plotted graphs in the same csv/excel, is there a way to do it

    • @MattMacarty
      @MattMacarty  4 ปีที่แล้ว

      If I understand you correctly you want to place one of the plots from Python into an Excel workbook. You can export the graph as a graphic file, but it would be static. To save it's plt.savefig("path_and_filename")
      You can save as .jpg or .png or pretty much any of the common graphic formats.

    • @electronikmale
      @electronikmale 4 ปีที่แล้ว

      Thanks for response.
      Can I plot matplotlib charts directly into the source excel file instead of plotting and then saving in png/jpg format. If not, is there any other library that can be used for this purpose.

  • @bhushantayade7984
    @bhushantayade7984 3 ปีที่แล้ว

    how to overlay both graphs??

    • @MattMacarty
      @MattMacarty  3 ปีที่แล้ว

      You mean so they appear on different scales? You can set a second scale.

  • @RATANAGARWALITINFORMER
    @RATANAGARWALITINFORMER 3 ปีที่แล้ว

    helping

  • @BadassBikerOwns
    @BadassBikerOwns ปีที่แล้ว

    Vin Diesel, is that you?