[Xion Mentoring] Mohon demonstrasikan penggunaan Matplotlib yang sering dipakai #824
-
Di kelas DWV telah diajarkan basic plot. boleh dibantu di demonstrasikan teknik2 visualisasi yang sering digunakan menggunakan matplotlib. Menggunakan dataset yang 'stock' yang kemaren. Terima kasih. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
Dear @ammaralwandi97 Pertanyaan Anda telah kami terima dan sedang kami usahakan terkait solusinya. Mohon kesediaannya untuk menunggu, terima kasih. Best regards, |
Beta Was this translation helpful? Give feedback.
-
Dear @ammaralwandi97 , Terkait penggunaan matplotlib, dapat dieksplorasi dari referensi berikut: https://matplotlib.org/stable/plot_types/index.html. Link tersebut berisi jenis-jenis plot yang dapat dibuat menggunakan matplotlib dan contoh code nya. Untuk visualisasi yang lebih custom, beberapa contoh dapat dilihat pada https://www.data-to-viz.com/. Silakan klik salah satu jenis plot, kemudian klik tombol Selamat mencoba! Best regards, |
Beta Was this translation helpful? Give feedback.
-
Dear @ammaralwandi97 , # 1. Lineplot: pergerakan harga Close AAPL, GOOGL, dan TSLA
tesla = stock['Close']
# plot data
plt.plot(tesla.index, tesla['AAPL'], label="Saham Apple")
plt.plot(tesla.index, tesla['GOOGL'], label="Saham Google")
plt.plot(tesla.index, tesla['TSLA'], label="Saham Tesla")
# mengatur legend, title, xlabel, ylabel
plt.legend(loc="upper left")
plt.xlabel('Waktu')
plt.ylabel('Harga Close')
plt.title('Perbandingan Harga Close Saham AAPL, GOOGL, dan TSLA Januari 2018 - November 2023', fontweight="bold") # 2. Barplot: perbandingan CoV
# mengambil nilai coefficient of variation
coef_of_var = stock['High'].std()/stock['High'].mean()
plt.bar(x = coef_of_var.index, height = coef_of_var)
# mengatur title, xlabel, ylabel
plt.xlabel('Perusahaan')
plt.ylabel('CoV')
plt.title('Perbandingan CoV Saham AAPL, GOOGL, dan TSLA', fontweight="bold") # 3. Histogram: distribusi harga Low TSLA
low_tesla = stock['Low']['TSLA']
plt.hist(low_tesla)
plt.xlabel('Harga Low')
plt.ylabel('Frekuensi')
plt.title('Distribusi Harga Low TSLA', fontweight="bold") # 4. Boxplot: distribusi harga Low
plt.boxplot(stock['Low'], showmeans=True, showcaps=True, showbox=True, showfliers=True)
plt.xticks([1,2,3],['AAPL','GOOGL','TSLA'])
plt.xlabel('Perusahaan')
plt.ylabel('Harga Low')
plt.title('Distribusi Harga Low AAPL, GOOGL, TSLA', fontweight="bold") Semoga jawaban ini dapat membantu. Best regards, |
Beta Was this translation helpful? Give feedback.
Dear @ammaralwandi97 ,
Berikut kami lampirkan kode contoh implementasi untuk membuat lineplot, barplot, histogram, dan boxplot.