Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More Parameter Options #30

Open
aidenguinnip opened this issue Jan 12, 2024 · 4 comments
Open

More Parameter Options #30

aidenguinnip opened this issue Jan 12, 2024 · 4 comments
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@aidenguinnip
Copy link

It'd be great if there were more parameter options such as:

  • Format of days (y-axis)
  • Format of months (x-axis)
@brunorosilva
Copy link
Owner

Hey @aidenguinnip , thanks for the suggestion.
Do you think that a parameter for each where you provide a list would be good enough for your use cases? This is really simple for me to implement and I can include it in the next release, but you can use the workaround below

Sample plot (In the examples folder)

import numpy as np
import pandas as pd

from plotly_calplot.calplot import calplot, month_calplot

# mock setup
dummy_start_date = "2019-01-01"
dummy_end_date = "2022-10-03"
dummy_df = pd.DataFrame(
    {
        "ds": pd.date_range(dummy_start_date, dummy_end_date),
        "value": np.random.randint(
            -10,
            30,
            (pd.to_datetime(dummy_end_date) - pd.to_datetime(dummy_start_date)).days
            + 1,
        ),
    }
)

fig1 = calplot(
    dummy_df,
    x="ds",
    y="value",
)

fig1.show()
image

Changing the weekday name

years_amt = dummy_df.ds.dt.year.max() - dummy_df.ds.dt.year.min() + 1
new_tickets = ["new", "tickets", "test", "nice", "foo", "bar", "zoo"]
for i in range(1, years_amt+1): # plotly's index starts at 1
    fig1.update_layout(**{f"yaxis{i}_ticktext": new_tickets})
image

Changing the month name to french

years_amt = dummy_df.ds.dt.year.max() - dummy_df.ds.dt.year.min() + 1
new_tickets = ["janvier", "février", "mars", "avril", "mai", "juin",
               "juillet", "août", "septembre", "octobre", "novembre", "décembre"]
for i in range(1, years_amt+1):
    fig1.update_layout(**{f"xaxis{i}_ticktext": new_tickets})
image

@aidenguinnip
Copy link
Author

I suppose that could work, but I was thinking of something less manual. I'm not necessarily trying to change the text away from a day or month, but instead to specify the datetime format using existing codes like these: https://docs.python.org/3/library/datetime.html#strftime-and-strptime-format-codes

An example would be:

fig1 = calplot(
    dummy_df,
    x="ds",
    y="value",
    xaxis_text_format="%b", # Result: Jan
    yaxis_text_format="%A", # Result: Sunday
)

@brunorosilva
Copy link
Owner

Nice suggestion, this seems doable right away. I'll put it on my todo list, thanks.

@brunorosilva brunorosilva self-assigned this Jan 12, 2024
@brunorosilva brunorosilva added enhancement New feature or request good first issue Good for newcomers labels Jan 12, 2024
@aidenguinnip
Copy link
Author

aidenguinnip commented Jan 13, 2024

I forgot to mention another parameter suggestion:

  • Choosing the start day.

Currently it starts with Monday at the top, but some people (like myself) like to start with Sunday. So having the option would be useful.

I know that will cause issues with ISO weeks but it's worth the thought.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants