简体   繁体   English

如何从python中的散点图中删除空白空间

[英]How to remove empty space from a scatter plot in python

I have data that I am plotting similar to the example shown我有我正在绘制的类似于所示示例的数据

#Data: Example data
x_data = [24.48,24.65,19.14,23.61,22.96,24.48,24.73]
y_data = [24.50,24.50,19.15,23.58,22.93,24.48,24.73]
plt.scatter(x_data, y_data, color = 'green', marker = '+', label = 'Example data')
plt.title('Example Data Plotted')
plt.xlabel('X_data')
plt.ylabel('Y_data')
plt.legend()
plt.show()

As you can see the lowest number is 19.14.如您所见,最低数字是 19.14。 How do I get it to plot this data between somthing like 18 and 25 instead of what it does now where it starts from 0. I want to remove all the white space below the lowest number in this list.我如何让它在 18 和 25 之间绘制此数据,而不是它现在从 0 开始的位置。我想删除此列表中最低数字下方的所有空白。

你应该使用:

plt.axes(xlim=(min(x_data),max(x_data)))
...
plt.xlim(18, 25) #adjust as you like
plt.ylim(18, 25) #adjust as you like
plt.show()

Check the example here检查这里的例子

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM