1

I've tried looking around to solve my issue, and some answers state that the zorder of Matplotlib have bugs and others say that it works for them. Regardless, here's the image and code that have been causing problems:

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


fig = plt.figure()

ax = fig.add_subplot(111, projection='3d')
ax.set_xlim(0, 7)
ax.set_ylim(0, 7)
ax.set_zlim(0, 7)
ax.view_init(elev=20, azim=32)

# u
ax.quiver(0, 0, 0, 1, 1, 0, color='C0', arrow_length_ratio=0.1, 
label=r'$\vec{u}$', zorder=10)

# v
ax.quiver(0, 0, 0, 2, 2, 0, color='C1', arrow_length_ratio=0.1, 
label=r'$\vec{v}$', zorder=0)

plt.legend()
ax.set_xlabel(r'$x$', fontsize='large')
ax.set_ylabel(r'$y$', fontsize='large')
ax.set_zlabel(r'$z$', fontsize='large')

plt.show()

This code produces the following image:

enter image description here

I want the blue arrow to be on top of the orange one. Specifying the zorder doesn't seem to work. Would anybody be kind enough to give me some tips and advice?

Thanks.

Sean
  • 2,890
  • 8
  • 36
  • 78
  • 1
    `zorder` is ignored in 3D plots (which makes sense as you define z explicitly), see [here](https://stackoverflow.com/questions/37611023/3d-parametric-curve-in-matplotlib-does-not-respect-zorder-workaround). My first idea was to simply raise the blue error by a small quantity (e.g. 0.01), but the results are not convincing. – cheersmate Feb 20 '19 at 07:39

1 Answers1

0

A possible solution, that would make you U vector stand out, is to change it's thickness so that it is slightly larger than vector V. The way to do it would be with linewidths argument, see Change size of arrows using matplotlib quiver. In your case something like:

# u
ax.quiver(0, 0, 0, 1, 1, 0, color='C0', arrow_length_ratio=0.1, linewidths=2.5,
label=r'$\vec{u}$', zorder=10) 

# v
ax.quiver(0, 0, 0, 2, 2, 0, color='C1', arrow_length_ratio=0.1, linewidths=1., 
label=r'$\vec{v}$', zorder=0)

Although, I realize that it might not be exactly what you want to do.

vezeli
  • 336
  • 2
  • 8