如何在散点图中以偶数间隔更改 x 轴值?
How to change x axis value with even interval in scatter plot?
x = [101.52762499 105.79521102 103.5158705 93.55296605 108.73719223 98.57426097 98.73552014 79.88138657 91.71042366 114.15815465]
y = [107.83168825 93.11360106 102.49196148 97.84879532 114.41714004 97.39079067 111.35664058 76.97523782 88.63047332 90.11216039]
我想做一个散点图,它显示带有 x 值的回归线
从 x 数据的最小值到最大值均匀地跨越 100 个区间。
我需要使用什么代码来改变 x 轴?
m,c = np.polyfit(x,y,1) #this is to find the best fit line
plt.plot(x, m*x + c) # this to plot the best fit line
plt.plot(x,y,'o') # this is to plot in
我厌倦了使用 plt.xticks(0,200)
但它给了我一条错误消息
TypeError: 'int' 类型的对象没有 len()
以下代码放置 x 个刻度以在第一个值和最后一个值之间创建 100 个大小相等的间隔。
import numpy as np
from matplotlib import pyplot as plt
x = np.array([101.52762499, 105.79521102, 103.5158705, 93.55296605, 108.73719223, 98.57426097, 98.73552014, 79.88138657, 91.71042366, 114.15815465])
y = np.array([107.83168825, 93.11360106, 102.49196148, 97.84879532, 114.41714004, 97.39079067, 111.35664058, 76.97523782, 88.63047332, 90.11216039])
m, c = np.polyfit(x, y, 1) # this is to find the best fit line
plt.figure(figsize=(15, 4))
plt.plot(x, m * x + c) # this to plot the best fit line
plt.plot(x, y, 'o') # this is to plot in
bins = np.linspace(x.min(), x.max(), 101) # 100 equally-sized intervals
plt.xticks(bins, rotation=90)
plt.grid(True, axis='x') # the grid lines show the 100 intervals of the xticks
plt.margins(x=0.02) # less whitespace left and right
plt.tight_layout()
plt.show()
x = [101.52762499 105.79521102 103.5158705 93.55296605 108.73719223 98.57426097 98.73552014 79.88138657 91.71042366 114.15815465]
y = [107.83168825 93.11360106 102.49196148 97.84879532 114.41714004 97.39079067 111.35664058 76.97523782 88.63047332 90.11216039]
我想做一个散点图,它显示带有 x 值的回归线 从 x 数据的最小值到最大值均匀地跨越 100 个区间。
我需要使用什么代码来改变 x 轴?
m,c = np.polyfit(x,y,1) #this is to find the best fit line
plt.plot(x, m*x + c) # this to plot the best fit line
plt.plot(x,y,'o') # this is to plot in
我厌倦了使用 plt.xticks(0,200)
但它给了我一条错误消息
TypeError: 'int' 类型的对象没有 len()
以下代码放置 x 个刻度以在第一个值和最后一个值之间创建 100 个大小相等的间隔。
import numpy as np
from matplotlib import pyplot as plt
x = np.array([101.52762499, 105.79521102, 103.5158705, 93.55296605, 108.73719223, 98.57426097, 98.73552014, 79.88138657, 91.71042366, 114.15815465])
y = np.array([107.83168825, 93.11360106, 102.49196148, 97.84879532, 114.41714004, 97.39079067, 111.35664058, 76.97523782, 88.63047332, 90.11216039])
m, c = np.polyfit(x, y, 1) # this is to find the best fit line
plt.figure(figsize=(15, 4))
plt.plot(x, m * x + c) # this to plot the best fit line
plt.plot(x, y, 'o') # this is to plot in
bins = np.linspace(x.min(), x.max(), 101) # 100 equally-sized intervals
plt.xticks(bins, rotation=90)
plt.grid(True, axis='x') # the grid lines show the 100 intervals of the xticks
plt.margins(x=0.02) # less whitespace left and right
plt.tight_layout()
plt.show()