1

I play around with the example from here. enter image description here

I want to increase the size of the arrows at the ends of x-axis and y-axis. I found this:

set_arrowstyle(“->,size=1.5”) set_arrowstyle(“->”, size=1.5)

So next I tried:

ax.axis["xzero"].set_axisline_style("->",  size=5)

But it doesn't help me.

2 Answers 2

1

The problem comes with the use of a jupyter notebook and its inline backend. So you will get the correct output if using the %matplotlib notebook backend. (You need to restart the kernel for that.)

%matplotlib notebook
from mpl_toolkits.axisartist.axislines import SubplotZero
import matplotlib.pyplot as plt
import numpy as np


fig = plt.figure(1)
ax = SubplotZero(fig, 111)
fig.add_subplot(ax)

for direction in ["xzero", "yzero"]:
    # adds arrows at the ends of each axis
    ax.axis[direction].set_axisline_style("-|>", size=5)

    # adds X and Y-axis from the origin
    ax.axis[direction].set_visible(True)

for direction in ["left", "right", "bottom", "top"]:
    # hides borders
    ax.axis[direction].set_visible(False)

x = np.linspace(-0.5, 1., 100)
ax.plot(x, np.sin(x*np.pi))

plt.show()

enter image description here

If you want /need to use the %matplotlib inline backend, you may need to revert some of the settings, such that the arrows are not cropped from the figure.

  1. The default setting for creating the png figure is the use of the bbox_inches="tight" option. This can be reverted via

    %config InlineBackend.print_figure_kwargs = {'bbox_inches':None}
    
  2. The default figure size, dpi and subplot parameters are different. Reverting those can be done via

    plt.rcdefaults() 
    

Due to a bug in Iypthon the rcParameters should not be set in the first cell of the notebook.

Hence

# Cell 1

%matplotlib inline
%config InlineBackend.print_figure_kwargs = {'bbox_inches':None}

# Cell 2
import matplotlib.pyplot as plt
plt.rcdefaults() 
from mpl_toolkits.axisartist.axislines import SubplotZero
import numpy as np

fig = plt.figure(1)

ax = SubplotZero(fig, 111)
fig.add_subplot(ax)

for direction in ["xzero", "yzero"]:
    # adds arrows at the ends of each axis
    ax.axis[direction].set_axisline_style("-|>", size=5)

    # adds X and Y-axis from the origin
    ax.axis[direction].set_visible(True)

for direction in ["left", "right", "bottom", "top"]:
    # hides borders
    ax.axis[direction].set_visible(False)

x = np.linspace(-0.5, 1., 100)
ax.plot(x, np.sin(x*np.pi))

plt.show()

enter image description here

2
1

The size parameter has to be within the quotes. You have passed it outside the quotes after a comma. Use the following

ax.axis[direction].set_axisline_style("-|>, size=4")

enter image description here

Complete code from the official website

from mpl_toolkits.axisartist.axislines import SubplotZero
import matplotlib.pyplot as plt
import numpy as np

if 1:
    fig = plt.figure(1)
    ax = SubplotZero(fig, 111)
    fig.add_subplot(ax)

    for direction in ["xzero", "yzero"]:
        # adds arrows at the ends of each axis
        ax.axis[direction].set_axisline_style("-|>, size=4") # <--- modified here

        # adds X and Y-axis from the origin
        ax.axis[direction].set_visible(True)

    for direction in ["left", "right", "bottom", "top"]:
        # hides borders
        ax.axis[direction].set_visible(False)

    x = np.linspace(-0.5, 1., 100)
    ax.plot(x, np.sin(x*np.pi))
    plt.show()
7
  • It should work outside the quotes as well. In which version does it not work as expected? Mar 29, 2019 at 21:16
  • @ImportanceOfBeingErnest '2.0.2' Mar 29, 2019 at 21:19
  • @ImportanceOfBeingErnest: Oh yes, you are right. I am on 2.2.2. Works both ways for me
    – Sheldore
    Mar 29, 2019 at 21:21
  • Mhh, even in 2.0.2 I cannot reproduce this, meaning, both notations are working fine in 2.0.2 as well. Mar 29, 2019 at 21:22
  • @Roma You are not showing a runnable code. I suspect you have something else in your code which prevents this from working. Mar 29, 2019 at 21:23

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.