-
Notifications
You must be signed in to change notification settings - Fork 3
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
Missing zorder? #22
Comments
Right now, images are handled differently than other objects on the Canvas. This is because matplotlib has some issues with aliasing when displaying some images, and because it cannot efficiently show images encoded as pdfs without a raster conversion. So, all objects on the Canvas use the standard matplotlib zorder except the images. Images always use a higher zorder than everything else. Relative to each other, images added first are underneath images added later. (So in your example, the smaller logo would be below the bigger logo.) But both are on top of other objects. Unfortunately, including images in the same z ordering as other objects would require some pretty substantial changes in matplotlib before it could be supported this in CanD. I will keep this open in case changes in matplotlib allow a better solution in the future. |
I see, thanks, that is very unfortunate. Is there any way around this? You mentioned pdf and that it wouldn't work well either (if I understood you correctly), what about svg or other formats? |
If the image you want to display is a raster (not a pdf) and you don't care about antialiasing, you can create an axis and then use ax.imshow. E.g., based on your example, from urllib.request import urlretrieve
urlretrieve("https://raw.githubusercontent.com/mwshinn/CanD/master/cand-logo.png", "_logo.png")
from cand import Canvas, Point, Vector
import imageio
c = Canvas(10, 8, "cm")
im = imageio.imread("_logo.png")
ax = c.add_axis("logoax", Point(1, 3, "cm"), Point(5, 7, "cm"))
ax.imshow(im)
ax.axis("off")
c.add_text("In front", Point(0.3, .8), weight="bold", size=13, zorder=100)
c.add_text("Behind", Point(0.3, .5), weight="bold", size=13, zorder=-100)
c.show() |
That works great, thanks! |
Hi @mwshinn ,
Maybe I have missed it, but I cannot find zorder. How can I specify the order of items plot on canvas? Let's take the following example. I want to load and add an image and on top of it place text. I can do it by creating a separate
unitname
and then add the text there (middle image). But what if I want to add the text relative to the canvas like in the example of the left image? I still want the text above (on top of) the image which I'd do withzorder
. How can I do it here?The text was updated successfully, but these errors were encountered: