[Matplotlib-users] Categorical variables and twinx make basically no sense

AJ M ajm8671 at gmail.com
Thu Mar 14 04:56:38 EDT 2019


Great, thanks for the reply. I tried the NaN solution during my tinkering
but thought I should somehow be getting away without having to recreate the
axes in the same dimensions, since it's not required when using integers.
Just making sure I wasn't missing anything more obvious

On Thu, Mar 14, 2019 at 12:29 AM Jody Klymak <jklymak at uvic.ca> wrote:

>
>
> On Mar 13, 2019, at  21:40 PM, AJ M <ajm8671 at gmail.com> wrote:
>
> The only conclusion I can come to is that matplotlib treats these values
> differently, and converts the text arrays to integers under the hood
> without trying to align them.
>
>
> Thats basically correct to my understanding - the twin axes is a new axes
> that shares it’s xlimits with the old one, but we don’t have any way of
> passing “categories” from one axes to the next, so it carries its own list
> of category->integer conversion that gets made anew when you call scatter.
> The first axes is the one that gets the tick labels.
>
> You *may* be able to pass the converter to the second axes, but I’m not
> sure.
>
> Easier would be to just do the following:
>
> ```python
>
> import matplotlib.pyplot as plt
> import numpy as np
>
> y1 = [5, np.NaN, 6, np.NaN, 15]
> y2 = [100, 200, 300, 400, 500]
>
> x = ['apples','carrots','bananas','watermelon','cheerios']
>
> fig, ax = plt.subplots()
> ax.scatter(x, y2)
> ax2 = ax.twinx()
> ax2.scatter(x, y1, color = "orange")
> plt.show()
> ```
>
> Cheers, Jody
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20190314/e8d28920/attachment.html>


More information about the Matplotlib-users mailing list