Matplotlib connect scatterplot points with line - Python
I think @Evert has the right answer:
plt.scatter(dates,values)
plt.plot(dates, values)
plt.show()
Which is pretty much the same as
plt.plot(dates, values, '-o')
plt.show()
You can replace -o
with another suitable format string as described in the documentation.
You can also split the choices of line and marker styles using the linestyle=
and marker=
keyword arguments.
Plot Numbers Instead of Points Using Matplotlib Scatterplot
You can just plot text anywhere you want, but you have to set the limits of the image manually by calling .xlim()
and .ylim()
import numpy as np
import matplotlib.pyplot as plt
centroidCoords = [(7.210123936676805, -0.0014481952154823),
(5.817327756517152, -1.0513260084561042),
(5.603133733696165, -2.7765635631249412),
(4.500525247710033, -0.8659667639805515),
(3.9999999999880367, -2.089987631283091)]
textCoord = [f"{x:.2f} {y:.2f}" for x, y in centroidCoords]
x, y = np.array(centroidCoords).T
for col, row, t in zip(x, y, textCoord):
plt.text(col, row, t, fontsize=10, color="red")
plt.xlim(min(x)-1, max(x)+1)
plt.ylim(min(y)-1, max(y)+1)
plt.show()
Python Scatter Plot: Cannot connect points
Scatter plot just plots the dots, if you want to connect them. You can useplot()
function with same arguments of scatter
plt.scatter(x,y)
plt.plot(x, y)
plt.show()
Related Topics
Numpy.Where() Detailed, Step-By-Step Explanation/Examples
Weird Behavior: Lambda Inside List Comprehension
How to Set "Camera Position" for 3D Plots Using Python/Matplotlib
How to Print Utf-8 Encoded Text to the Console in Python < 3
Python Module to Change System Date and Time
Python How to Read N Number of Lines at a Time
Overwriting File in Ziparchive
Region: Ioerror: [Errno 22] Invalid Mode ('W') or Filename
How to Use 'Cv2.Findcontours' in Different Opencv Versions
Restricting the Value in Tkinter Entry Widget
Python Integer Incrementing with ++
Check for Identical Rows in Different Numpy Arrays
How to Add Hours to Current Time in Python
Difference Between Python3 and Python3M Executables
How to Install a Python Package from Within Ipython
Remove Duplicate Rows from Pandas Dataframe Where Only Some Columns Have the Same Value