Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

168
Visualizações
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

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Use axes.set_xbounds() or axes.set_xlim() (docs found here and here respectively). Both methods appear identical in function, but set_xlim has more functionality, should you require it. So your new modified code using only axisartist is:

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

# Data
x = np.random.random(10)
y = np.random.random(10)
x.sort()
y.sort()

# Creating figure, plot
fig = plt.figure()
ax = fig.add_subplot(axes_class=axisartist.Axes)
ax.scatter(x, y, marker="o")

# Formatting axes
ax.axis['right'].set_visible(False)
ax.axis['top'].set_visible(False)
ax.axis['left'].major_ticklabels.set_pad(10)
ax.axis['bottom'].major_ticklabels.set_pad(10)

# Setting axis limits
ax.set_xlim(left=0.2, right = 0.5)
ax.set_ylim(bottom=0, top = 0.7)

plt.tight_layout()
plt.draw()
plt.show()
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda