Apr-28-2024, 05:26 PM
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:
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:
Thanks.
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:The date range spans from 2016-12-25 to 2021-01-01
- All I Want For Christmas Is You by Mariah Carey
- Rockin' Around The Christmas Tree by Brenda Lee
- Jingle Bell Rock by Bobby Helms
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.