On Thu, Jan 6, 2011 at 11:47 AM, Benjamin Root <ben.r...@ou.edu> wrote:

> On Thu, Jan 6, 2011 at 12:57 AM, Sebastian Voigt <svo...@gmx.de> wrote:
>
>>  Am 06.01.2011 02:14, schrieb Benjamin Root:
>>
>> On Wed, Jan 5, 2011 at 6:15 PM, Sebastian Voigt <svo...@gmx.de> wrote:
>>
>>> I've been running into the well known rendering problems with mplot3d's
>>> bar3d function. After two days of trying to get acceptable results
>>> without success: Is it possible to simply disable z-sorting (whoops)?
>>>
>>> I want to generate static plots from experimental data, all using the
>>> same perspective, so I know the order of the bars to be plotted. It's a
>>> no-brainer to provide the data vectors in this appropriate order, which
>>> I tried too - didn't work. Even if I provide explicit zorders for all
>>> Poly3dCollections in axes.collections (single-plotting each bar),
>>> everything gets messed up after showing the plot window.
>>>
>>> So is there any way to create the bars just in the order of the data
>>> vectors passed to bar3d (or keep the order/zorder in axes.collections)?
>>>
>>>
>>>     - Sebastian Voigt -
>>>
>>>
>> There are well-known rendering issues with mplot3d in general, but I am
>> not aware of one with respect to bar3d.  Can you please include a image of
>> the rendering defect that you are seeing?
>>
>> And no, there is no way to disable z-sorting that I am aware of because it
>> is inherent in matplotlib's system.  mplot3d merely utilizes the drawing
>> facilities that matplotlib provides.
>>
>> Ben Root
>>
>>
>> It's exactly the same problem as described in
>>
>>
>> http://www.mail-archive.com/matplotlib-users@lists.sourceforge.net/msg15243.html
>>
>> see the second sample pic in this post. If I cannot disable z-sorting, how
>> can I control it? Artist have a set_zorder() method, but providing correct
>> z-levels for all my artists seems to be ignored.
>>
>> Sebastian
>>
>
> Sebastian,  looking at those images, I have to wonder if there is a bug in
> how bar3d is reporting the z-order.  These rendering mistakes do not seem to
> follow the same patterns that I have seen with manually setting polygon
> objects.  I will take a deeper look into it.
>
> Ben Root
>
>

Ok, I have figure out what is wrong here.  First of all, thank you for
pointing out this whole issue, because my investigations lead me to realize
some other bugs that are currently in the development trunk (I have to see
if they are in the 1.0.1 branch as well).

As for the issue with bar3d.  The graphs look much better when you plot each
row of bars (or even better if you plot each bar separately).  This is
because bar3d creates a Poly3DCollection and will do its best to sort the
collection elements internally with respect to each other.  However, when
you have two objects from two separate Poly3DCollections (or any two 3D
collection objects, for that matter) that occupy the same region in space,
then you will have problems.

Each Poly3DCollection object reports a scalar zsort value that is supposed
to represent the zsort value of all its elements.  This is fine if the
collections are spatially distinct, or if the scalar zsort value is equal to
the zsort value of all the elements.

Try out the attached modified script.  You can see that by looping through
the bars, you get a much better result (although it is still not perfect due
to the already established issues).  I am not exactly sure how to resolve
this, but at least it is documented here for posterity.

Ben Root
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import numpy as np

np.random.seed(42)


x, y = np.random.rand(2, 100) * 4
hist, xedges, yedges = np.histogram2d(x, y, bins=4)

elements = (len(xedges) - 1) * (len(yedges) - 1)
xpos, ypos = np.meshgrid(xedges[:-1]+0.25, yedges[:-1]+0.25)

xpos = xpos.flatten()
ypos = ypos.flatten()
zpos = np.zeros(elements)

dxs = 0.5 * np.ones_like(zpos)
dys = dxs.copy()
dzs = hist.flatten()

dxs = dxs*0.5
xpos = xpos - dxs



fig = plt.figure()
ax = Axes3D(fig)

for xs, ys, zs, dx, dy, dz in zip(xpos, ypos, zpos, dxs, dys, dzs) :
    ax.bar3d(xs, ys, zs, dx, dy, dz, color='r', zsort='max')
    ax.bar3d(xs+dx, ys, zs, dx, dy, dz, color='b', zsort='max')

ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')
ax.set_title("Individualized Bars (Good)")


fig = plt.figure()
ax = Axes3D(fig)

ax.bar3d(xpos, ypos, zpos, dxs, dys, dzs, color='r', zsort='max')
ax.bar3d(xpos+dxs, ypos, zpos, dxs, dys, dzs, color='b', zsort='max')

ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')
ax.set_title("Large Group Bars (Bad)")

plt.show()
------------------------------------------------------------------------------
Learn how Oracle Real Application Clusters (RAC) One Node allows customers
to consolidate database storage, standardize their database environment, and, 
should the need arise, upgrade to a full multi-node Oracle RAC database 
without downtime or disruption
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to