couldnt remove origin point in matplotlib polycollection

2024/10/8 2:22:40

I have tried an example with PolyCollection from matplotlib tutorials and noticed one strange thing. I couldn't remove this points from axes origin see fig. How do I manage this?

enter image description here

from mpl_toolkits.mplot3d import Axes3D
from matplotlib.collections import PolyCollection
from matplotlib.colors import colorConverter
import matplotlib.pyplot as plt
import numpy as npfig = plt.figure()
ax = fig.gca(projection='3d')cc = lambda arg: colorConverter.to_rgba(arg, alpha=0.6)xs = np.arange(5, 10, 0.4)
verts = []
zs = [0.0, 1.0, 2.0, 3.0]
for z in zs:ys = np.random.rand(len(xs))ys[0], ys[-1] = 0.1, 0verts.append(list(zip(xs, ys)))poly = PolyCollection(verts, facecolors = [cc('r'), cc('g'), cc('b'),cc('y')])
poly.set_alpha(0.7)
ax.add_collection3d(poly, zs=zs, zdir='y')ax.set_xlabel('X')
ax.set_xlim3d(0, 10)
ax.set_ylabel('Y')
ax.set_ylim3d(-1, 4)
ax.set_zlabel('Z')
ax.set_zlim3d(0, 1)plt.show()
Answer

This is a bug with the explicit closing feature of PolyCollection.

For now, turn that off, and you'll get what I think is the result you expect:

poly = PolyCollection(verts, facecolors = [cc('r'), cc('g'), cc('b'),cc('y')], closed=False)

The only problem here is that you shouldn't get the results you expect while running this, because the polygon shouldn't be closed. This is another, related bug with the 3D code. In any case, this only affects the line around the edge, and in your example it barely makes any difference (I originally thought it was correctly not closed until I increased the linewidth).

PolyCollection uses path.Path objects to store the vertexes, and for closed polygons, uses the CLOSEPOLY vertex code, which cleanly closes the path (no overlap in the line).

The 3D projection code for PolyCollections seems to be rather a hack which takes your PolyCollection, extracts the paths, takes the vertexes from those paths, throwing the codes for those vertexes away and assuming they're all real vertex coordinates, and then directly modifies the vertexes on your original PolyCollection to use new paths that have 2D screen projected coordinates with no codes... and regardless of your settings, are closed.

I've filed this as issue #2045.

https://en.xdnf.cn/q/70170.html

Related Q&A

How to read .odt using Python? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.Want to improve this question? Add details and clarify the problem by editing this post.Closed 3 years ago.The com…

Modifying Django settings in tests

From Django docs:You shouldn’t alter settings in your applications at runtime. Forexample, don’t do this in a view:from django.conf import settingssettings.DEBUG = True # Dont do this!The only plac…

How To Use Django Cycle Tag

This hopefully is a pretty easy question. My endgoal is to be able to view my database entries in a table which I can sort via the column headers. I have read the documentation on cycle tags, but dont …

Multiple linear regression with python

I would like to calculate multiple linear regression with python. I found this code for simple linear regressionimport numpy as npfrom matplotlib.pyplot import *x = np.array([1, 2, 3, 4, 5])y = np.arra…

How to find source of error in Python Pickle on massive object

Ive taken over somebodys code for a fairly large project. Im trying to save program state, and theres one massive object which stores pretty much all the other objects. Im trying to pickle this object,…

What is the most idiomatic way to index an object with a boolean array in pandas?

I am particularly talking about Pandas version 0.11 as I am busy replacing my uses of .ix with either .loc or .iloc. I like the fact that differentiating between .loc and .iloc communicates whether I a…

Error: Command failed with rc=65536 python and mod_wsgi

im having this problem: im runing pythonbrew to get python2.7, and so i re-compiled mod_wsgi to use the 2.7 python. to that end, i followed this tutorial: code.google.com/p/modwsgi/wiki/QuickInstallati…

Why cant I freeze_panes on the xlsxwriter object pandas is creating for me?

I have a class whose objects contain pandas dataframes (self.before, and self.after below) and a save() method which uses xlsxwriter to export the data (which has two worksheets, "before" and…

Python multiprocessing pipe recv() doc unclear or did I miss anything?

I have been learning how to use the Python multiprocessing module recently, and reading the official doc. In 16.6.1.2. Exchanging objects between processes there is a simple example about using pipe t…

How would you unit test this SQLAlchemy Core query/function?

Im working on learning how to unit test properly. Given this function...def get_user_details(req_user_id):users = sa.Table(users, db.metadata, autoload=True)s = sa.select([users.c.username,users.c.favo…