Python package to plot charts from a user's LastFM data. LastCharts downloads a users entire listing history using the LastFM Rest API, and includes methods to create pre-defined charts.
- Python. not sure what is minimum version required. I have used 3.12.
- To generate bar chart races you need at least one of:
- FFmpeg for exporting video formats like mp4
- ImageMagick for exporting gifs
- A LastFM API account, it is very easy to setup. See your existing LastFM API accounts here.
https://github.com/Habarug/LastCharts.git
cd LastCharts
pip install .
In Jupyter/python shell:
import lastcharts
lc = lastcharts.LastCharts(YOUR API KEY, YOUR USERNAME)lc.load_scrobbles(user = ENTER USERNAME)- If no username is provided it will use your username.
- Go grab a snack. The first time you run this for a user it may run for a very long time, depending on how long the users history is. You can only load 200 scrobbles at a time from LastFM, and the API is heavily rate limited. The next time you run this command only new scrobbles will be downloaded, and it will be much faster. Being able to only download new scrobbles each time was one of my main motivations when starting this.
Once the scrobbles are loaded you can start plotting. The first time you plot a stacked bar plot album covers are downloaded to your computer, so it may take a little while to run the first time.
fig, ax = lc.stacked_bar_plot(
startDate = None, # Optional start date for plot, format ISO 8601 (YYYY-MM-DD)
endDate = None, # Optional end date for plot, format ISO 8601 (YYYY-MM-DD)
nArtists = 15, # Change how many artists are included
artLimitCoefficient = 0.05 # Cofficient to determine which albums will include cover art.
# 0.05 => only albums with at least 5% of the highest bar will get a cover art
)This is very cool, but quite slow and memory intensive, so you may have to tweak the parameters a bit to get the results you want. The dates are filtered before plotting if the history is long, as it otherwise made me run out of memory. Adjust length, f_period and **{steps_per_period} to find your ideal tradeoff between length, smoothness and performance. For more information on **bcr_options check the bar_chart_race documentation.
lc.bar_chart_race(
column = "artist", # Can select artist, album or track
startDate = None, # Optional start date for plot, format ISO 8601 (YYYY-MM-DD)
endDate = None, # Optional end date for plot, format ISO 8601 (YYYY-MM-DD)
length = 10, # Length of the resulting video in seconds
f_periods = 15, # Number of dates to plot per second
format = "gif", # Format to save, gif, mp4,...
skip_empty_dates = False, # Option to skip dates with no scrobbles
**{"steps_per_period" : 4, # Number of frames per period
"fig_kwargs": { # kwargs for fig
"dpi": 100}, # dpi of images
} # Custom arguments for the bar_chart_race. More available
)Similar information to the bar chart race, but in image form! Not as exciting, but honestly this is more informative.
fig, ax = lc.plot_rank_timeline(
column="artist", # Can select artist, album or track
nTimesteps=10, # Number of timesteps to use (often looks messy with too many)
nPlot=10, # Number of e.g. artists to show at once.
nInclude=200, # Number of your top e.g. artists to include in the analysis
startDate=None, # Optional start date for plot, format ISO 8601 (YYYY-MM-DD)
endDate=None, # Optional end date for plot, format ISO 8601 (YYYY-MM-DD)
)Presents how many unique artists/albums/tracks you have listened to each year, as well as how many new were discovered and what fraction of scrobbles were from new discoveries.
fig, ax = lc.plot_yearly_discoveries()Bar plot of top artists, album or tracks, with optional time filtering.
lc.plot_top(
column = "album", # Artist, album or track
nBars = 15, # Number of bars to plot
startDate = None, # Optional start date for plot, format ISO 8601 (YYYY-MM-DD)
endDate = None # Optional end date for plot, format ISO 8601 (YYYY-MM-DD)
)Simple method for getting the exact number of scrobbles an artist/album/track, optionally for a specific timeframe. Can provide any combination of artist/album/track. For artist only one is required, but if you want to find the scrobbles for a specific track it might be a good idea to also provide the artist. Example
lc.get_scrobbles_for(
artist = None,
album = None,
track = "Shotgun",
startDate = None,
endDate = None
)
Number of scrobbles for Shotgun: 126
lc.get_scrobbles_for(
artist = "Soccer Mommy",
album = None,
track = "Shotgun",
startDate = None,
endDate = None
)
Number of scrobbles for Soccer Mommy Shotgun: 44




