I did search through a variety of examples. Many of these examples feature edge cases where the poster is trying to do something more than a simple plot. I also looked for a lot of help.
I just want to have a plot where date is on the x-axis, a count is on the y-axis and the dots are colored by category. In the beginning, I got close but for some reason that plot showed dates before when I wanted it to start.
This post was "Closed" but after some work and using suggestions, the plot works. Code working code is below
# Plot
# Load libraries
import seaborn as sns
import matplotlib.pyplot as plt
# Create sample data set
pen = sns.load_dataset('penguins')
pen['dates'] = pd.date_range(start = '2012-01-01', end = '2013-06-01')[:344]
pen = pen[['dates','flipper_length_mm','sex']].dropna()
# Use a mask to subset obs if needed
#https://stackoverflow.com/questions/29370057/select-dataframe-rows-between-two-dates
mask = (pen['dates'] >= '2012-04-01')
pen2 = pen.loc[mask]
# Create Plots
fig, ax = plt.subplots(figsize=(12,12))
ax = sns.scatterplot(x='dates', y='flipper_length_mm', data=pen2, hue="sex", ax = ax)
# Limit date range
# https://stackoverflow.com/questions/53963816/seaborn-scatterplot-is-plotting-more-dates-than-exist-in-the-original-data
ax.set(xlim = ('2012-04-01', '2013-01-01'))
Here is a working plotnine version of the same concept.
from plotnine import *
from mizani.breaks import date_breaks
from mizani.formatters import date_format
(
ggplot(pen, aes(x='dates', y = 'flipper_length_mm', color = 'sex'))
+ geom_point()
+ scale_x_datetime(breaks = date_breaks('1 month'))
+ theme(axis_text_x = element_text(rotation = 90, hjust = 1))
+ labs(title = "Penguins")
)