Change Axis tick interval

I’m trying to find a way to change the tick interval on a chart axis. I’ve tried in Line Plot and also Line Plot (Plotly), but I just get a thick black line with labels overlapping - see image below

The labels are YYYY-WW (year-week number) but in string format.

As an alternative to experimenting with this as a string, I tried to put them back to date format but can’t find a way to do this. They have to be week numbers because I import multiple datasets that I can only match on a weekly basis because they have different day-dates. I can’t figure out how to reverse the process I use to get YYYY-WW from actual dates, which is:: Extract date&time fields (to get Y & W) >> Number to string (as prep for next step) >>> string manipulation (to concatenate to get YYYY-WW).

From other charts I have, I think Line Plot will handle tick spacing if it’s in date format.

A solution either way (for date or string labels) would be much appreciated.
Thanks
John

Dear @nojrebrab

Below follows a possible solution for strings.

I don’t know how to solve this purely with the Line Plot node configuration. However, the line plot simply plots the points as they appear in the table going top to bottom. In contrast with a scatter plot, it does not care what the x-labels are. So, if you want to prevent label overlap by having fewer labels, as a workaround you can simply replace unwanted labels by empty strings in the table. For example:
image

Results in:
image

If we want fewer labels on the X-axis, we can insert a Java Snippet into the workflow:
image

With the following configuration:
image

This yields the following table:
image

Which results in a plot with fewer tick labels:
image

Just increase the “2” in the Java Snippet code with higher numbers if you want even fewer labels to appear.

Best
Aswin

2 Likes

Hello @nojrebrab,

check out this topic:

Br,
Ivan

1 Like

Hi Aswin

Thank you for your help, and for your clear explanation.

That’s worked for me, I just need to play around with it a bit more to try to fit in more than annual ticks

image.png

Maybe Knime can add this to their line plot nodes?

Thanks again

John

Thanks Ivan
I’d looked at this before I posted my plea for help. With my limited programming skills, I wasn’t able to find a way to make this work easily and it looked like it was going to take me a lot of time to figure out how to work through CSS properly. Aswin’s 1-line solution has worked so I’ll go with that, and perhaps experiment with CSS when time permits.
Thanks
John

1 Like

Hello @nojrebrab,

I see. Glad to hear that worked for you. Also to mention there is already a ticket to enhance labeling options on plots and I have noted your request there.

Br,
Ivan

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.