Friday, 5 November 2021

How to set bounds for spinal line with axisartist?

How can i set the bounds of axisartist.axis[].line?

With the normal API, its possible to set bounds of the axis spine with ax.spines['right'].set_bounds(low=0.01,high=0.1)

But axisartist does not have a "spines" object, instead, spinal lines are implemented with ax.axis['left'].line, which does not have a get_bounds and set_bounds method

Example


import numpy as np
import matplotlib.pyplot as plt
import mpl_toolkits.axisartist as axisartist
import seaborn as sns

use_artist = True

x = np.random.random(10)
y = np.random.random(10)

x.sort()
y.sort()

if use_artist:
    fig = plt.figure()
    ax = fig.add_subplot(axes_class=axisartist.Axes)
else:
    fig, ax = plt.subplots()
    
ax.scatter(x, y, marker="o")

if use_artist:
    ax.axis['right'].set_visible(False)
    ax.axis['top'].set_visible(False)
    
    # HOW TO SET BOUNDS OF ax.axis['left'].line here?
    
else:
    sns.despine()
    ax.spines['left'].set_bounds(ax.get_yticks()[1], ax.get_yticks()[-2])
    ax.spines['bottom'].set_bounds(ax.get_xticks()[1], ax.get_xticks()[-2])

plt.tight_layout()
plt.draw()
plt.show()

Here are examples without and with axisartist

Example with normal API Example with axisartist



from How to set bounds for spinal line with axisartist?

No comments:

Post a Comment