Home > Software design >  matplolib arrow is creating a weird vertical line at the arrow head
matplolib arrow is creating a weird vertical line at the arrow head

Time:02-04

I am trying to place an axis arrow.

For some reason, when I place an arrow at my plot it also creates a huge vertical line orders of magnitude bigger.

I am instantiating the arrow like this:

#examples of what would be found within x_length, set, y_length, and ax on the anomalous case
x_length=[30000000000.0]
y_length=[[7.7e-09, 1.613e-08]]
set=0
ax=plt.subplot(1,2,1)

#The problematic statement by itself
arrow=ax.arrow(x_length[set], 0, 0.04*x_length[set], 0, shape='full',head_width=max(y_length[set])*0.04,head_length=0.04*x_length[set],length_includes_head=True,color='black', zorder=2)

It works properly when y values are big (let's say "t_values>1"). Although, when the y values are small (let's say "y_values<1e-6"), this problem emerges.

The figures below show a case that what is expected happen and another with the anomalous behavior:

Based on this Figure, I think the lines always is drawn, but only noticed when y values are small

With large values it works as expected

Note: Using the zoom feature, it's possible to verify that the arrow is placed as expected although, this weird line is also placed at the arrow's head.

I have already tried to modify every single parameter, also applying constanst values instead of variables. Although, nothing worked. Moreover, even if a inclined arrow is placed, the unpleasant line is always vertical.

CodePudding user response:

I solved the problem.

This weird line was infinitesimal arrow tail width. So, replacing the arrow method with the width arg included solved the problem. Since the default width is 1e-3, that was the reason why the issue only happened for plot in some orders of magnitude greater then this default width.

            ax.arrow(x_max[set], 0, 0.04*x_length[set], 0,shape='full',head_width=y_length[set][i]*0.04,head_length=0.04*x_length[set],length_includes_head=True,color='black', zorder=2,width=max(y_length[set])*0.04)
  • Related