Python Forum
Visualizing musician chart performance and ranking using pandas and matplotlib
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Visualizing musician chart performance and ranking using pandas and matplotlib
#1
I am enrolled in a not for school credit Udemy course by Colt Steele on data anlaysis in Python using common data visulization modules like pandas, matplotlib, plotly, and seaborn.

The task I am working on calls students to:

Quote:Create a line plot seen in the image attached. It shows the chart performance (rank) of the following songs:
  • All I Want For Christmas Is You by Mariah Carey
  • Rockin' Around The Christmas Tree by Brenda Lee
  • Jingle Bell Rock by Bobby Helms
The date range spans from 2016-12-25 to 2021-01-01
Notice the customized x-axis tick marks, the legend, the title, and the axis labels! Also the figure is 10x7
To invert the y-axis, use plt.gca().invert_yaxis()

This screenshot shows the expected data visualization and end product. See here:
   

This screenshot shows my valiant but evidentlyvery broken feeble attempt:
   

Here is my code snippet:

import pandas as pd
# import plotly.express as px
import matplotlib.pyplot as plt

hot_billboard = pd.read_csv('data/billboard_charts.csv')
# hot_billboard.info()

fig, ax = plt.subplots()
hot_billboard_dates_parsed = hot_billboard.loc[(hot_billboard['date'] >= '2016-12-25') & (hot_billboard['date'] <= '2020-01-01')]

rockin = hot_billboard_dates_parsed[hot_billboard_dates_parsed['song'] == "Rockin' Around The Christmas Tree"]
alliwant = hot_billboard_dates_parsed[hot_billboard_dates_parsed['song'] == "All I Want For Christmas Is You"]
jingle = hot_billboard_dates_parsed[hot_billboard_dates_parsed['song'] == "Jingle Bell Rock"]

jingle.plot.line(x='date',y='rank',ax=ax, color='green', legend=False)
alliwant.plot.line(x='date',y='rank',ax=ax, color='red', legend=False)
rockin.plot.line(x='date',y='rank',ax=ax, color='blue', legend=False)

plt.gca().invert_yaxis()
Take note: The instructor asks students to decorate the plot with custom x/y ticks, a legend, and use certain colors. I am not concerned with these cosmetic configurations at this point. One step at a time. For now I am focused on resolving the overlapping x-axis increments and the red (alliwant) data points from extending beyond the paramaters of the x-axis. Can anyone on these forums identify what variable or method I may be (mis)using which is causing to skew the red line? What do I need to modify in my code to tell Python, pandas, matplotlib to keep all three musical artists' #1 rank Series data within the bounds of the datetime x-axis (Christmas 2016-2021)?

Thanks.
Reply


Messages In This Thread
Visualizing musician chart performance and ranking using pandas and matplotlib - by Drone4four - Apr-28-2024, 05:26 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  matplotlib chart text font misery with 5x8 dot matrix Knabbler 6 520 Jun-04-2024, 07:30 AM
Last Post: ebn852_pan
Question I’m trying to create a Power BI Matplotlib quadrant chart and I’m a little stumped. Nidwolff 1 655 Mar-04-2024, 06:07 AM
Last Post: Danishhafeez
  visualizing huge correation matrix erdemath 3 2,235 Oct-13-2021, 09:44 AM
Last Post: erdemath
  Rename labels of a bar chart Matplotlib smalatray 1 4,519 Jul-01-2020, 01:48 AM
Last Post: hussainmujtaba
  Matplotlib bar chart ollarch 0 1,512 Mar-04-2020, 10:45 AM
Last Post: ollarch
  Spacing pie chart colours evenly in matplotlib? Giovanni_diJacopo 1 3,466 Jul-12-2019, 12:31 PM
Last Post: scidam

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020