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

Suggestion: add option to specify x-axis limits #18

Open
willov opened this issue Jun 9, 2021 · 7 comments
Open

Suggestion: add option to specify x-axis limits #18

willov opened this issue Jun 9, 2021 · 7 comments

Comments

@willov
Copy link

willov commented Jun 9, 2021

Thanks for a great package!

It would be great if it was possible to specify the limit on the x-axis.
In my case, I am comparing two groups in two different figures, and the scales are different.
Which in turn makes it hard to compare the figures. Being able to set the range would be great.
Or, at least set it to +/- 100%.

Thanks again!

@nmalkin
Copy link
Owner

nmalkin commented Jun 10, 2021

Thank you for the suggestion! I started thinking a little about how this could be implemented.

My first idea was to see if this could be done entirely with matplotlib handles:

ax1 = plot_likert.plot_likert(data1, scale);
ax2 = plot_likert.plot_likert(data2, scale);
ax2.set_xlim(ax1.get_xlim())

Unfortunately, this only sort of works. The plot is scaled to the right size, but the tick marks look bad (because they're laid out assuming the original scale):
image

You can actually make them look better with the xtick_interval argument we introduced a while back.

ax1 = plot_likert.plot_likert(data1, scale);
ax2 = plot_likert.plot_counts(plot_likert.likert_counts(data2, scale),
                              scale,
                              xtick_interval=5);
ax2.set_xlim(ax.get_xlim())

image

I think the main issue with this approach is that the plot will always be left-aligned, so even if it's the same scale as the other plot, it's still not a perfect side-by-side comparison.

Doing this the right way (i.e., allowing the x-axis to be specified as an argument) will probably require messing with how the padding in the generated plot gets calculated.

@willov
Copy link
Author

willov commented Jun 10, 2021

Thanks for the quick reply!
I agree that the left alignment isn't perfect, but for my application it is perfectly fine.
I had missed the xtick_interval argument, that surely helps.

Maybe I should open another issue, but having the argument in plot_likert.plot_likert would be nice as well :)

Again, thanks for a nice package!

nmalkin added a commit that referenced this issue Jun 11, 2021
based on discussion in #18

It was previously only available in plot_counts.
@nmalkin
Copy link
Owner

nmalkin commented Jun 11, 2021

Maybe I should open another issue, but having the argument in plot_likert.plot_likert would be nice as well :)

I went ahead and did this; it seemed quite easy to do, no reason not to.

I'll go ahead and keep this issue open for now, I think, in case someone wants to contribute an improvement, or if I get around to it eventually.

Thanks again for the suggestion, and I'm glad the library has been useful for you!

@maxdeze
Copy link

maxdeze commented Sep 7, 2022

Hi,
great package! :)
I was wonder if there is any update for the possibility of setting the x axis (when plotting the %) to +/- 100%.
(e.g., 100%, 75%, 50%, 25%, 0, 25%, 50%, 75%, 100%)

thanks!

@nmalkin
Copy link
Owner

nmalkin commented Sep 8, 2022

Hi @maxdeze,

I threw together a quick proof-of-concept in 55721a8 on the set-axis-100 branch.

You can try it out yourself with:
pip install git+https://github.com/nmalkin/plot-likert.git@set-axis-100

That code special-cases the [-100%,100%] situation; I'll need to think more about how to make it generic so it works for other custom axis limits.

I welcome PRs on this (from anyone) because I don't know when I'll get to it next.

@maxdeze
Copy link

maxdeze commented Sep 8, 2022

amazing! thanks

@H53-OOF
Copy link

H53-OOF commented Mar 27, 2024

Any chance the above workaround could be added to 0.50?
In general a symmetrical axis limits option would be nice since likert plots commonly represent balanced scales. Equal axis limits either side of zero makes them easier to interpret at a glance.
Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants