简体   繁体   English

Python-Matplotlib-保持轴平整和线性,并在网格上绘制点

[英]Python - Matplotlib - Keep axes even and linear and have points plotted on grid

So, I've scoured the internet for a long time and come up with nothing. 因此,我已经搜寻了很长时间的互联网,却一无所获。

Suppose I have this: 假设我有这个:

x = [35,86,34,55]
y = [11,84,73,26]

plt.plot(x,y)
plt.show()

This is a simplified version (without adding titles etc.) 这是简化版本(不添加标题等)

I want to know how I can create a grid with points (not connected) at certain co-ordinates. 我想知道如何创建在某些坐标处具有点(未连接)的网格。 Easy enough. 很简单。 But I would like the grid axes to be even. 但是我希望网格轴是均匀的。 So, rather than the x-axis progressing as 35, 86, 34, 55, it would progress from 1 to 100 and those x-axis points would be plotted on the grid. 因此,x轴不是从35、86、34、55前进,而是从1到100前进,并且这些x轴点将绘制在网格上。 I have tried the following: 我尝试了以下方法:

plt.xlim()
# and
plt.axis('equal')

and I have come up with no results. 我没有结果。

The resulting graph consists of a 45* line with and x- and y-axis non-linear. 生成的图形由45 *线组成,其中x轴和y轴为非线性。 Any help would be extremely appreciated. 任何帮助将不胜感激。

Thanks, Reece 谢谢,里斯

It is not clear from your question and comments what your final figure should look like. 从您的问题和评论中尚不清楚最终数字应该是什么样。 Based on my interpretation of your words, you want the grid lines to pass through only the specified data points. 根据我对单词的解释,您希望网格线仅通过指定的数据点。 To do so, you need to first set the x- and y-ticks at those coordinate positions and then turn the grid on. 为此,您需要先在这些坐标位置设置x和y勾号,然后打开网格。

x = [25,45,63,4]
y = [74,73,90,7]

plt.plot(x,y, 'ko')
plt.xlim(0, 100)
plt.xticks(x)
plt.yticks(y)
plt.grid()

在此处输入图片说明

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

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