You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I expected the colours to be correctly picked, meaning an increasing number of different colours in each subplot from top to bottom with each bar in a row roughly the same size (since that's what Z should look like).
Matplotlib version
Operating system: Arch Linux
Matplotlib version: 3.1.3
Matplotlib backend (print(matplotlib.get_backend())): PGF with PDF output, GTK3Agg
There is a beating of two different discretisations, the manual one and the one from contour, right?
So if you create an image plot, i.e. replace ax.contourf(xx, yy, Z, cmap=cm) by ax.imshow(Z, aspect="auto", cmap=cm) it will show the expected colors
If using a contour plot, the contours will only be at the discretization levels if exactly those levels are chosen when calling it (else it wouldn't know about that explicit desire).
Well, I only used that data to simplify the MWE, in my actual use case I'm trying to visualise the results of an SVM. And I beg you pardon but if I have data with $n$ distinct $Z$ values and say there will be $n$ levels, the results of contourf should show $n$ differently coloured areas.
The colored areas are in between the levels. So to get n colors one needs n+1 levels. But if an integer, the levels argument will only determine an approximate number, provided by the output of a MaxNLocator. See issue #12729 and PR #16534 for the corresponding docstring fix.
@ImportanceOfBeingErnest Thank you very much for your patience with me and the explanations where I misunderstood the documentation. Everything seems clear to me now :)
Activity
Skillmon commentedon Mar 3, 2020
Oh, and even with
levels=i+2the colours aren't set reliably.ImportanceOfBeingErnest commentedon Mar 3, 2020
There is a beating of two different discretisations, the manual one and the one from contour, right?
So if you create an image plot, i.e. replace
ax.contourf(xx, yy, Z, cmap=cm)byax.imshow(Z, aspect="auto", cmap=cm)it will show the expected colorsIf using a contour plot, the contours will only be at the discretization levels if exactly those levels are chosen when calling it (else it wouldn't know about that explicit desire).
Closing this, as there is no bug apparent here, but feel free to discuss further if I'm misunderstanding.
Skillmon commentedon Mar 3, 2020
Well, I only used that data to simplify the MWE, in my actual use case I'm trying to visualise the results of an SVM. And I beg you pardon but if I have data with$n$ distinct $Z$ values and say there will be $n$ levels, the results of $n$ differently coloured areas.
contourfshould showImportanceOfBeingErnest commentedon Mar 3, 2020
The colored areas are in between the levels. So to get n colors one needs n+1 levels. But if an integer, the
levelsargument will only determine an approximate number, provided by the output of aMaxNLocator. See issue #12729 and PR #16534 for the corresponding docstring fix.Skillmon commentedon Mar 3, 2020
Ok, specifying as a list does work, still I find the behaviour with$Z$ has exactly $n$ distinct levels.
levels=<int>weird whentimhoffm commentedon Mar 3, 2020
Just as a remark, a similar plot can be created in a single axes using a horizontal bar chart:
See https://matplotlib.org/gallery/lines_bars_and_markers/horizontal_barchart_distribution.html
ImportanceOfBeingErnest commentedon Mar 3, 2020
The reason for this is that you rarely want some odd levels like
but rather some nice levels like
Skillmon commentedon Mar 3, 2020
@timhoffm this is just an oversimplification for the sake of an MWE, I need
contourfas it is used to show the class borders of an SVM.Skillmon commentedon Mar 3, 2020
@ImportanceOfBeingErnest Thank you very much for your patience with me and the explanations where I misunderstood the documentation. Everything seems clear to me now :)