我正在尝试使用x轴绘制一些数据,显示数据点之间的等距间距。
代码:
def newline_or_execute_outer(shell):
def newline_or_execute(event):
"""When the user presses return, insert a newline or execute the code."""
b = event.current_buffer
d = b.document
if b.complete_state:
cc = b.complete_state.current_completion
if cc:
b.apply_completion(cc)
else:
b.cancel_completion()
return
# If there's only one line, treat it as if the cursor is at the end.
# See https://github.com/ipython/ipython/issues/10425
if d.line_count == 1:
check_text = d.text
else:
check_text = d.text[:d.cursor_position]
status, indent = shell.input_splitter.check_complete(check_text + '\n')
if not (d.on_last_line or
d.cursor_position_row >= d.line_count - d.empty_line_count_at_the_end()
):
b.insert_text('\n' + (' ' * (indent or 0)))
return
if (status != 'incomplete') and b.accept_action.is_returnable:
b.accept_action.validate_and_handle(event.cli, b)
else:
b.insert_text('\n' + (' ' * (indent or 0)))
return newline_or_execute
因此每两个相邻点之间的距离相等。
答案 0 :(得分:2)
因此,您的图表似乎仅用于表示目的。 x轴上的数字不需要在比例上。要绘制此图,您必须创建一个x
轴列表,该列表实际上是按比例缩放的,只需用sizes
列表的元素替换其标签即可。以下代码显示了如何执行此操作
#!/usr/bin/env python
from matplotlib import pyplot as plt
sizes = [1400, 1600, 1700, 1875, 1100, 1550, 2350, 2450, 1425, 1700]
prices = [245, 312, 279, 308, 199, 219, 405, 324, 319, 255]
plt.ylim([0, 500])
plt.xlabel("sizes")
plt.ylabel("prices")
x = [a for a in range(len(sizes))]
plt.scatter(x,prices)
plt.xticks(x, sizes)
plt.show()