设置X和Y限制在我想重新创建的数字中无法工作
我想成为这样的人物
我有下面的代码,
import numpy as np
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
import cartopy.mpl.ticker as cmt
import xarray as xr
import matplotlib.ticker as ticker
from shapely import vectorized
import pandas as pd
import csv
# Open file
grl = xr.open_dataset('/Users/jacobgarcia/Desktop/Master en Meteorologia/TFM/Trabajo fin de master/OUTPUTS/output/ens1/0/yelmo1d.nc')
topo = xr.open_dataset('/Users/jacobgarcia/Desktop/Master en Meteorologia/TFM/Trabajo fin de master/Greenland/GRL-16KM/GRL-16KM_TOPO-M17.nc')
#My data
A_ice = grl["A_ice"][0]
V_ice = grl["V_ice"][0]
# Data points from goelzer
points = pd.read_csv("/Users/jacobgarcia/Desktop/Master en Meteorologia/TFM/Figures/points.csv")
diamonds = pd.read_csv("/Users/jacobgarcia/Desktop/Master en Meteorologia/TFM/Figures/diamonds.csv")
#Convert to list of tuples
with open('/Users/jacobgarcia/Desktop/Master en Meteorologia/TFM/Figures/points.csv', newline='') as f:
reader = csv.reader(f)
points = [tuple(row) for row in reader]
with open('/Users/jacobgarcia/Desktop/Master en Meteorologia/TFM/Figures/diamonds.csv', newline='') as f:
reader = csv.reader(f)
diamonds = [tuple(row) for row in reader]
# Now start the plots
# Create a figure
fig = plt.figure()
# Add a subplot
ax = fig.add_subplot()
ax.set_title("Grounded ice area and grounded volume")
plt.rcParams["figure.figsize"] = [7.00, 3.50]
plt.rcParams["figure.autolayout"] = True
x_mydata = A_ice
y_mydata = V_ice
plt.xlim(0, 5)
plt.ylim(0, 5)
plt.grid()
plt.plot(x_mydata, y_mydata, marker="^", markersize=20, markeredgecolor="red", markerfacecolor="red")
plt.plot(float(points[0][0]),float(points[0][1]), marker="o", markersize=14, markeredgecolor="blue", markerfacecolor="blue")
plt.plot(float(points[1][0]),float(points[1][1]), marker="o", markersize=14, markeredgecolor="blue", markerfacecolor="blue")
plt.plot(float(points[2][0]),float(points[2][1]), marker="o", markersize=14, markeredgecolor="blue", markerfacecolor="blue")
plt.plot(float(points[3][0]),float(points[3][1]), marker="o", markersize=14, markeredgecolor="blue", markerfacecolor="blue")
plt.plot(float(points[4][0]),float(points[4][1]), marker="o", markersize=14, markeredgecolor="blue", markerfacecolor="blue")
plt.plot(float(points[5][0]),float(points[5][1]), marker="o", markersize=14, markeredgecolor="blue", markerfacecolor="blue")
plt.plot(float(points[6][0]),float(points[6][1]), marker="o", markersize=14, markeredgecolor="blue", markerfacecolor="blue")
plt.plot(float(points[7][0]),float(points[7][1]), marker="o", markersize=14, markeredgecolor="blue", markerfacecolor="blue")
plt.plot(float(points[8][0]),float(points[8][1]), marker="o", markersize=14, markeredgecolor="blue", markerfacecolor="blue")
plt.plot(float(points[9][0]),float(points[9][1]), marker="o", markersize=14, markeredgecolor="blue", markerfacecolor="blue")
plt.plot(float(points[10][0]),float(points[10][1]), marker="o", markersize=14, markeredgecolor="blue", markerfacecolor="blue")
plt.plot(float(points[11][0]),float(points[11][1]), marker="o", markersize=14, markeredgecolor="blue", markerfacecolor="blue")
plt.plot(float(points[12][0]),float(points[12][1]), marker="o", markersize=14, markeredgecolor="blue", markerfacecolor="blue")
plt.plot(float(points[13][0]),float(points[13][1]), marker="o", markersize=14, markeredgecolor="blue", markerfacecolor="blue")
plt.plot(float(diamonds[0][0]),float(diamonds[0][1]), marker="D", markersize=14, markeredgecolor="green", markerfacecolor="green")
plt.plot(float(diamonds[1][0]),float(diamonds[1][1]), marker="D", markersize=14, markeredgecolor="green", markerfacecolor="green")
plt.show()
x_axis = np.arange(1.6,2,1)
y_axis = np.arange(1.6,3.3,1)
plt.xticks(x_axis)
plt.xticks(y_axis)
#ax.set_xticks(x_axis)
#ax.set_yticks(y_axis)
这是我得到的结果。这些点是接近的,因为由于某些原因,轴线限制尚未设置为上图中的一个。
PS:A_ICE和H_ICE是我自己的数据点,而CSV文件点和钻石来自另一个数据集
任何帮助都将不胜感激!谢谢!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来您正在调用.show(),然后设置tick。这可能是一个问题。
您真正想要的是 > 和Xlim。这将控制轴的最小值和最大值。
代码的结尾看起来更像:
Looks like you are calling .show() and then setting the ticks. That could be a problem.
What you really want is
matplotlib.pyplot.ylim
and xlim. That will control the min and max values of the axes.The end of the code would look more like: