简体   繁体   English

如何让matplotlib显示所有x坐标?

[英]How to make matplotlib show all x coordinates?

For example in the following code: 例如,在以下代码中:

import numpy as np
import matplotlib.pyplot as plt

N = 10
x = [1,2,3,4,5,6,7,8,9,10]
y = np.random.rand(N)

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

I get the following plot 我得到以下情节

在此输入图像描述

as you can see, in the x axis only the even values appear. 如您所见,在x轴上只显示偶数值。 How to force matplotlib to show all values, that is 1 2 3 4 5 6 7 8 9 10? 如何强制matplotlib显示所有值,即1 2 3 4 5 6 7 8 9 10?

Use plt.xticks(x) . 使用plt.xticks(x) See the documentation . 请参阅文档

Note that using only the input values for ticks will usually be confusing to a viewer. 请注意,仅使用刻度线的输入值通常会使观看者感到困惑。 It makes more sense to use evenly spaced ticks. 使用均匀间隔的刻度更有意义。

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

相关问题 Pycharm:自动显示matplotlib的x / y坐标 - Pycharm: show x/y coordinates with matplotlib automatically Matplotlib:使范围内的所有值都显示在 x 轴上 - Matplotlib: Make all values in range show up on x axis 当x轴是字符串时,如何让python matplotlib显示x轴坐标(右上角) - How to make python matplotlib display x-axis coordinates (right corner) when x-axis is a string Matplotlib:如何让 imshow 从其他 numpy 数组读取 x、y 坐标? - Matplotlib: how to make imshow read x,y coordinates from other numpy arrays? 给定 x,y,z 坐标的数据,我将如何在 Matplotlib 中制作 3D 表面 plot? - How would I make a 3D surface plot in Matplotlib given this data of x,y,z coordinates? matplotlib 难以显示所有 x 刻度标签 - matplotlib difficult to show all x tick labels 如何显示 matplotlib 中的所有标签? - How to show all the labels in matplotlib? 为什么 x 坐标是时间戳列表,当鼠标移动(悬停)时,不显示为 matplotlib 中的坐标? - why x coordinates that's a list of timestamp, don't show as coordinates in matplotlib when mouse moves(hover)? 如何获取matplotlib文本(x,y,“ String”,bbox =…)轴坐标 - How to get matplotlib text(x, y, “String”, bbox=…) axis coordinates 如何使Matplotlib在X轴上显示日期而不在周末绘制空间 - How to make matplotlib show dates in x-axis without plotting spaces in weekends
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM