How to change the position of the graph in the figure in matplotlib

Asked

Viewed 43 times

-1

The graph became small and poorly positioned.

inserir a descrição da imagem aqui

for i in df.index:
    plt.plot(df.at[i,'x0'], df.at[i,'y0'], label=i)
    
# A e B
plt.axvline(x=ABx, ymin=0.1, ymax=0.55, linestyle = "dashed", color='gray')
plt.scatter(ABx,ABy, marker= 'o', color='black', s=20, alpha = 0.8)
plt.annotate('Ponto Crítico da Produção A e B (' + str(ABx) + ', ' + str(ABy) + ')', (ABx,ABy),
            textcoords="offset points", # how to position the text
            xytext=(20,0), # distance from text to points (x,y)
            ha='left' # horizontal alignment can be left, right or center
            )

# B e C
plt.axvline(x=BCx, ymin=0.1, ymax=0.4, linestyle = "dashed", color='gray')
plt.scatter(BCx,BCy, marker= 'o', color='black', s=20, alpha = 0.8)
plt.annotate('Ponto Crítico da Produção B e C (' + str(BCx) + ', ' + str(BCy) + ')', (BCx,BCy),
            textcoords="offset points", # how to position the text
            xytext=(20,0), # distance from text to points (x,y)
            ha='left' # horizontal alignment can be left, right or center
            )

x0, y0, r = 0, 0, ABx                    # dados do círculo
t = np.arange(0, 2*np.pi, 0.01)          # dominio da função (passo 0.01 para melhorar a precisão)
x = x0 + r * np.cos(t)                   # calculando X e Y
y = y0 + r * np.sin(t)
plt.plot(x, y, 'r-', linestyle = "dashed")

x0, y0, r = 0, 0, BCx                    # dados do círculo
t = np.arange(0, 2*np.pi, 0.01)          # dominio da função (passo 0.01 para melhorar a precisão)
x = x0 + r * np.cos(t)                   # calculando X e Y
y = y0 + r * np.sin(t)
plt.plot(x, y, 'r-', color='green', linestyle = "dashed")

plt.title('Von Thunen') 
plt.legend()
plt.ylabel('LUCRO LÍQUIDO')
plt.xlabel('DISTÂNCIA')
plt.axvline(x=0, ymin=0, ymax=1, linestyle = "solid", color='black')
plt.axhline(y=0, xmin=0.4, xmax=1, linestyle = "solid", color='black')

#plt.box(False)
plt.axis('equal')
#plt.axis([0, 40, 0, 70]) # [xmin, xmax, ymin, ymax]
plt.show()
  • It would help to have a portion or all of the dataset to replicate exactly

  • True, it’s my fault. The notebook is here: https://colab.research.google.com/drive/1xRPYWXjlq0DhQ1zRckhXrk0lGxAr0pI?usp=sharing and csv with the following data: https://drive.google.com/file/1GGbVw11izHDpUfPZD64BERGianb0w37/view?usp=sharing

  • I’m sorry, the csv you shared does not contain the columns the code accesses, e.g.: x0. To help you better I would have to replicate exactly the graph and the problem you have.

  • I don’t get it, but if that part is in the code it puts that part in the question too

  • Sorry, I should have made it easier from the beginning, I thought sharing the laptop would be easier. I add two columns X0 and Y0 to the Data Frame so: df['y0'] = list(zip(df.LB, df.CT*0))
df['x0'] = list(zip(df.LB*0, df.LB/df.CT))

  • Puts plt.figure(figsize=(15,8)) before the cycle goes and see if it solves the problem sff.

  • The size was excellent, but the chart is centered on the source (0.0) and I wanted to shift it all to the left because there is too much empty space left.

Show 2 more comments

1 answer

0

I found a solution. I plotted a point to the right of the graph, in (60.0), making the center of the graph no longer match the origin. It’s not the most elegant thing in the world but the result is infinitely better. inserir a descrição da imagem aqui

Browser other questions tagged

You are not signed in. Login or sign up in order to post.