Graphing your data

That should be the shrink=4 at line 10.
You could just play around with that value to try to get something better.

You can also erase the shrink=4 altogether (and the preceding comma) to get the default size (but I suspect it won’t look good either)

1 Like

that actually worked really well. :eyes:

hist_plot

2 Likes

I’m not sure. They don’t look aligned with the actual years :joy: There’s also that weird gap between 2021(?) and 2022.
Maybe shrink=0.8 or something like that?

Edit: But otherwise, if you don’t mind sharing your data after deleting your private notes (I can share code for that too), I could take a closer look.

It does interesting things, yes.
hist_plot

I thought, I’d shorten the time to when I actually started reading properly… Now I have even more spaces. :rofl:

I removed everything not necessary for the bar chart, but I can't find the issue
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
from datetime import datetime

def plot_stacked_hist(dt):
    fig, ax = plt.subplots()
    sns.histplot(data=dt, x="Year", palette="Set3", hue="Book Type",multiple="stack", shrink=.8, ax=ax, kde=False)
    fig.patch.set_facecolor('white')
    fig.savefig("hist_plot.png", bbox_inches='tight')
    plt.close(fig)

if __name__ == "__main__":
    import sys
    if len(sys.argv) < 2:
        printf("Usage:",sys.argv[0],"csv_file")
        exit()
    dat = pd.read_csv(sys.argv[1])
    dat["Date Finished"] = pd.to_datetime(dat["Date Finished"])
    finished = pd.DataFrame(dat[dat["Status"]=="finished"])
    finished["Year"] = list(map(lambda x: datetime.strptime(x.strftime("%Y"),"%Y"), finished["Date Finished"].dt.to_pydatetime()))
 
    plot_stacked_hist(finished)

at least, I no longer have error messages. :sweat_smile:
hist_plot

1 Like

Well, I should have fixed the error messages you had, but I have no clue about the histograms. I cannot reproduce your output :frowning:
If you feel like it, you can send me a message with the output of

pip3 freeze | grep -E 'matplotlib|seaborn|pandas'

(and your python version I guess) and I’ll try again with your settings.
(Your data may be informative too, actually, if you don’t mind sharing them)


Unrelated, but I have added some quality of life options
-d date allows the user to set the starting date for the last two plots
-p palette allows the user to set the color palette. Example: -p Set3

4 Likes

will do when I get home (if I don’t forget :see_no_evil:)
At some point I eliminated everything but the columns absolutely needed for this to work and put all dates within a year on January 1st and it was still producing the same graph. So, yeah. Likely my python setup is the cause, because I feel I have eliminated all other possibilities. :melting_face:

2 Likes

python 3.10.4

and apparently grep is a UNIX command not available on windows :melting_face:

I think, I’ll just have to live with this not working. But thank you anyways. :yellow_heart:

In the meantime, I have given in and conjured up a quick chart in libre.

image
Ugly colours, though… :see_no_evil:

1 Like

W… windows? Oof, I haven’t touched a windows OS since XP.

You can get the same info by running
python3 -m pip show matplotlib seaborn pandas

It’s just a bit more messy.

Edit: wait, is the graph correct? In the previous plot, you had stuff going back to 2010, but this one is just since 2018?
Ah you said you shortened the time.

I still wonder if it’s a problem with the years. If you can just add a
print(finished[“Year”])
at the end, maybe there’s something weird in there?

(ah, but it will probably cut off before we see anything of interest… Typing code on a smartphone is hell too, so I don’t want to propose something more involved for now)

EDIT2: okay, I think there’s definitely an issue since the bar stacks to ~80 in python but ~200 in Libre

2 Likes
Result
C:\Users\Julia>python -m pip show matplotlib seaborn pandas
Name: matplotlib
Version: 3.5.2
Summary: Python plotting package
Home-page: https://matplotlib.org
Author: John D. Hunter, Michael Droettboom
Author-email: matplotlib-users@python.org
License: PSF
Location: c:\users\julia\appdata\local\programs\python\python310\lib\site-packages
Requires: cycler, fonttools, kiwisolver, numpy, packaging, pillow, pyparsing, python-dateutil
Required-by: seaborn
---
Name: seaborn
Version: 0.13.0
Summary: Statistical data visualization
Home-page:
Author:
Author-email: Michael Waskom <mwaskom@gmail.com>
License:
Location: c:\users\julia\appdata\local\programs\python\python310\lib\site-packages
Requires: matplotlib, numpy, pandas
Required-by:
---
Name: pandas
Version: 1.4.2
Summary: Powerful data structures for data analysis, time series, and statistics
Home-page: https://pandas.pydata.org
Author: The Pandas Development Team
Author-email: pandas-dev@python.org
License: BSD-3-Clause
Location: c:\users\julia\appdata\local\programs\python\python310\lib\site-packages
Requires: numpy, python-dateutil, pytz
Required-by: seaborn

Yeah especially with Excel-like programmes you can quite easily have the axis simply start and end where you want. You don’t have to do anything to the data, you just change how the graph displays.

Apart from a very short time were we had dos(shell) and later OS/2, I have never used anything but windows. :sweat_smile: I am just a normie user. :melting_face: the only reason I have pythong is because there have been some script thingies I wanted to use. :see_no_evil:

1 Like

I tried with your library environment, but everything is fine on my end, so I assume that it is indeed a problem with your data.
You probably have something in there that I am not expecting (it’s not like I have the full range of everything Natively can generate…)

1 Like

This isn’t going to help any with the automation, but I just realised I should probably put some stuff into https://www.datawrapper.de/ and see if I can make any interesting graphs from there. Might be easier than Gcharts… or not, idk.

1 Like

I don’t know if this counts as a graph, but I made myself a fake “Spotify Wrapped” for my books/manga this year. It would be cool to eventually have more stats on genre and such now that we have tags. That could make for a more detailed “Wrapped”.

6 Likes

Given I (wholly unintentionally) got 3 books in a row featuring incest in some way this year I feel like this could be potentially hilarious :joy:

9 Likes

It’s definitely the sort of thing that having access to our data allows! I know goodreads stuff isn’t particularly useful but it does feel nice to look and be like ‘Oh right I read a 600+ page book this year’ and stuff like that

3 Likes

i’ve been working on automating a google sheet where all you have to do is dump your CSV and maybe rename it and pretty charts come out, but it’s slow going. it would probably be a lot easier in python etc.

in the meantime, here’s my scattergraph

11 Likes