@@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
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 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!
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.
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
@@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!
@@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.
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.
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?
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
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.
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
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?
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
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
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 Thank you, I did separate plots for them. One more question: how would I best visualize and calculate the correlation between two stocks?
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.
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.
# 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.
Yes, yfinance is actually a different module which is an alternative to the pandas_datareader.
❤❤ Thanks ya all
Your explanation is very clear. You are a great teacher! Thank you so much ^^
Thank you. Glad it helped.
This perfect. Short and sweet. Thanks for taking the time to make this.
Thanks. Glad it helped.
Just got what I was looking for. Thanks for explaining it perfectly!
Glad it helped
Excellent intro, this really helped, thank you.
Thanks. Glad it helped
Perfect introduction!! Just what i needed. Thank you!
glad it helped
Very clear and concise.
Glad it helped
I didn't get the answer I needed but this was excellent and I learned a lot of new things - thanks
Thanks. Glad it helped, but what were you looking for?
@@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
this is clear , thank you so much...
Glad it helped
very helpfull for my end semester task, terimakasih sir!
Glad it helped.
It saved my day🤗
I can't thank you enough🥺
Glad it helped
This is nice and simple but informative
Glad it helped
This is so good, short and easy to understand, 🤟
Thanks. Glad it helped
Really informative! Thx!
Glad it was helpful!
Thank You for this useful video :)
Glad it helped.
best video ever !!
glad it helped
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!
Hi no I haven't. You want support and resistance relative to what?
@@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!
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.
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
@@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!
@@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.
@@MattMacarty Fantastic! Just what I was looking for! Thank you, Matt.
Very useful, thanks.
Glad it was helpful!
nice flow of explanation, can you show me how to swap the axes ?
Thanks. You mean you want the lines to down to up instead of left to right?
@@MattMacarty I need labels on X-axis and Y-axis are interchanged..
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..?
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.
Have you tried the min method in pandas?
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?
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
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.
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
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?
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.
Could you tell me how I can ask it to plot from a certain date to another? Btw thanks for the great video
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
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
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
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
You should be able to make it graph to the edges by setting plt,xlim(min, max)
thank you
Glad it helped
Great! how can I put the lasts values (for the two stocks) in the grafic? thanks!
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
Can you plot for example the Closing price and the Volume in the same graph?
Yes you can do that. It may be much simpler to accomplish with subplots rather than in the same chart though.
@@MattMacarty Thank you, I did separate plots for them. One more question: how would I best visualize and calculate the correlation between two stocks?
Could you do this on big data?
You can but you probably want to limit the output to a small window of observations. matplotlib will struggle with large datasets
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
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.
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.
how to overlay both graphs??
You mean so they appear on different scales? You can set a second scale.
helping
Great
Vin Diesel, is that you?
LOL, I have heard that one before
Dude 😂😂😂😂