import yfinance as yf import pandas as pd f='stock_data.dat' df=yf.download('2330.TW', start='2022-01-01', end='2022-12-08') #df=yf.download(['2330.TW', '9914.TW', '2108.TW'], start='2022-11-01', end='2022-11-05') df=df[['High', 'Low', 'Volume']] df.to_csv('3_TW_stock_close_price.csv' ,sep='\t') use GD::Graph::Data; use GD::Graph::mixed; # Read in the data from a file my $data = GD::Graph::Data->new( ); # initialize $data->read(file => 'stock_data.dat'); # read in my $graph = new GD::Graph::mixed(900, 300) or die "Can't create graph!"; $graph->set( # Set the general attributes title => "TSMC Corp. stock 2022", types => [qw(area area bars)], dclrs => [qw(red white blue)], transparent => 0, ); $graph->set( # Set the attributes for the x-axis x_label => 'Day of Year', x_label_skip => 5, x_labels_vertical => 1, ); $graph->set( y_max_value => ($data->get_min_max_y_all( ))[1]+25, y_tick_number => 10, y_all_ticks => 1, y_number_format => sub { '$'.int(shift); }, ); # Set the legend $graph->set_legend(undef, undef, 'Volume is in thousands of shares traded'); $graph->set_legend_font(gdLargeFont); $graph->set(legend_placement => 'BL'); my $gd = $graph->plot( $data ) or die "Can't plot graph"; # Plot the data open OUT, '>', 'tsmc.png' or die "cannot open tsmc.png"; binmode(OUT); print OUT $gd->png(); close OUT;