Python Forum
Issue with ginput and adding points to an exisiting plot - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Issue with ginput and adding points to an exisiting plot (/thread-21750.html)



Issue with ginput and adding points to an exisiting plot - gaminer - Oct-12-2019

I am using ginput to plot additional points to an exisiting scatter plot, however when the new points are added the previously set x and y limits change. Attached is the code and visualizations to help explain the issue I am having.

#### CODE ####

import pandas as pd
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import numpy as np

#### Read CSV File ####
mb = pd.read_csv('CuerpoGeologico.csv')
topo = pd.read_csv('Superficie.csv')


#### Create Subplots ####

fig = plt.figure()

ax1 = fig.add_subplot(211)
ax2 = fig.add_subplot(234)
ax3 = fig.add_subplot(235)
ax4 = fig.add_subplot(236)

#### PLot Data ####

ax1.scatter(mb.x, mb.y, c = 'blue', s=10)
ax2.scatter(mb.x, mb.z, c = 'magenta', s=1)
ax3.scatter(mb.y, mb.z, c = 'magenta', s=1)
ax4.scatter(mb.x, mb.y, c = 'magenta', s=1)

#### Set Grid #####
ax1.grid()

#### Set Axis Limits and Ticks ####
ax1.set_xticks(np.arange(3000, 9000, 1000))
ax1.set_yticks(np.arange(4000, 9000, 1000))

ax2.set_xlim([3000, 8000])
ax2.set_xticks([4000, 6000, 8000])
ax2.set_yticks(np.arange(0, 5000, 1000))

ax3.set_xticks([4000, 6000, 8000])
ax3.set_yticks(np.arange(0, 5000, 1000))

ax4.set_xlim([3000, 8000])
ax4.set_xticks([4000, 6000, 8000])
ax4.set_yticks(np.arange(4000, 9000, 1000))

#### Set Axis Labels ####
ax1.set_xlabel('East')
ax1.set_ylabel('North')

ax2.set_xlabel('East')
ax2.set_ylabel('Elevation')

ax3.set_xlabel('North')
ax3.set_ylabel('Elevation')

ax4.set_xlabel('East')
ax4.set_ylabel('North')

fig.tight_layout()

#### Select Drillhole Locations ####

collars = plt.ginput(2)

x = []
y = []

for i in collars:               #Create list of x and y coordinates of collars 
    x.append(i[0])
    y.append(i[1])
    
ax1.scatter(x, y, c='black', marker='x')        #Plot drillhole collars


[Image: view?usp=sharing]

[Image: view?usp=sharing]

As you can see after the points are placed in Figure_1b that the plot zooms in and the axis limits change. I would like for the figure to maintain the format of Figure_1a after placing the points with ginput.