While I was working on a Python project, I needed to visualize sales growth data for different U.S. states. I wanted each line to show a dashed pattern with markers at specific points.
At first, I thought this would be a bit tricky. But once I explored the options in Matplotlib, I realized Python makes it incredibly simple. With just a few lines of code, I could create professional-looking dashed lines with markers that made my charts easier to read.
In this tutorial, I’ll walk you through different methods I use to create dashed lines with markers in Matplotlib. I’ll also share some customization tricks that I’ve learned over the years as a Python developer.
Methods to Use Dashed Lines with Markers in Python Matplotlib
Dashed lines help differentiate multiple data series in the same chart. Markers highlight important data points, making them stand out.
When combined, dashed lines with markers give your chart both clarity and style.
Method 1 – Basic Dashed Line with Markers in Python
The simplest way to plot a dashed line with markers is by using the linestyle and marker parameters in the plt.plot() function.
Here’s a Python example where I plot average monthly electricity usage data for California.
import matplotlib.pyplot as plt
# Sample data for electricity usage (California, in kWh)
months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
usage = [720, 650, 690, 710, 750, 770, 800, 820, 790, 760, 740, 730]
# Create dashed line with circular markers
plt.plot(months, usage, linestyle='--', marker='o', color='b', label='CA Usage')
plt.title("Average Monthly Electricity Usage in California")
plt.xlabel("Month")
plt.ylabel("Usage (kWh)")
plt.legend()
plt.grid(True)
plt.show()I executed the above example code and added the screenshot below.

In this Python code, I used linestyle=’–‘ for a dashed line and marker=’o’ for circular markers. This is the simplest way to make your Matplotlib chart visually appealing with minimal effort.
Method 2 – Custom Dash Pattern with Markers in Python
Sometimes, I need more control over the dash style. Python Matplotlib allows me to define a custom dash pattern using the dashes parameter.
Here’s an example with U.S. gasoline price data.
import matplotlib.pyplot as plt
# Sample data for average gasoline prices (USD per gallon)
weeks = list(range(1, 9))
prices = [3.85, 3.90, 3.95, 4.05, 4.10, 4.15, 4.20, 4.18]
# Create a dashed line with triangle markers and custom dash pattern
line, = plt.plot(weeks, prices, marker='^', color='g', label='Gasoline Price')
line.set_linestyle('--')
line.set_dashes([10, 5, 2, 5]) # Long dash, gap, short dash, gap
plt.title("Average Gasoline Prices in the USA (Weekly)")
plt.xlabel("Week")
plt.ylabel("Price (USD per Gallon)")
plt.legend()
plt.grid(True)
plt.show()I executed the above example code and added the screenshot below.

In this Python example, I defined a dash sequence [10, 5, 2, 5]. This means a long dash, a gap, a short dash, and another gap.
Method 3 – Multiple Dashed Lines with Different Markers in Python
When I compare multiple datasets, I often use different markers for each line. This makes it easier for the audience to distinguish between them.
Here’s an example comparing average rainfall in New York and Texas.
import matplotlib.pyplot as plt
# Sample data for rainfall (inches)
months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun"]
ny_rain = [3.1, 2.8, 3.5, 3.7, 4.1, 4.3]
tx_rain = [2.1, 2.3, 2.5, 3.0, 3.2, 3.5]
# Plot NY rainfall with dashed line and square markers
plt.plot(months, ny_rain, linestyle='--', marker='s', color='b', label='New York')
# Plot TX rainfall with dash-dot line and diamond markers
plt.plot(months, tx_rain, linestyle='-.', marker='D', color='r', label='Texas')
plt.title("Average Monthly Rainfall (NY vs TX)")
plt.xlabel("Month")
plt.ylabel("Rainfall (inches)")
plt.legend()
plt.grid(True)
plt.show()I executed the above example code and added the screenshot below.

In this Python code, I used square markers (‘s’) for New York and diamond markers (‘D’) for Texas. This method works great when presenting data comparisons to an audience.
Method 4 – Style Dashed Lines with Markers in Python
I often like to adjust marker size, line width, and colors for better readability. Python Matplotlib gives me full control over these properties.
Here’s an example with unemployment rates in the U.S.
import matplotlib.pyplot as plt
# Sample data for unemployment rate (%)
years = [2018, 2019, 2020, 2021, 2022]
rate = [3.9, 3.7, 8.1, 5.4, 3.6]
# Customize dashed line with markers
plt.plot(years, rate, linestyle='--', marker='o', color='purple',
markersize=10, linewidth=2, markerfacecolor='yellow',
markeredgecolor='black', label='Unemployment Rate')
plt.title("U.S. Unemployment Rate (2018-2022)")
plt.xlabel("Year")
plt.ylabel("Rate (%)")
plt.legend()
plt.grid(True)
plt.show()I executed the above example code and added the screenshot below.

In this Python example, I made the markers larger, filled them with yellow, and gave them a black border.
Method 5 – Use plot_date for Time Series with Dashed Lines and Markers in Python
For time series data, I often use plot_date() in Matplotlib. It works just like plot() but is optimized for dates.
Here’s an example with U.S. stock market closing prices.
import matplotlib.pyplot as plt
import datetime as dt
# Sample stock closing prices
dates = [dt.date(2023, 1, i) for i in range(2, 10)]
prices = [150, 153, 149, 155, 157, 160, 158, 162]
# Plot dashed line with markers on dates
plt.plot_date(dates, prices, linestyle='--', marker='o', color='navy', label='Stock Price')
plt.title("Stock Closing Prices (Sample Data)")
plt.xlabel("Date")
plt.ylabel("Price (USD)")
plt.legend()
plt.grid(True)
plt.tight_layout()
plt.show()In this Python code, I used plot_date() to handle dates directly. This method is especially useful for financial or economic datasets.
Extra Tips for Dashed Lines with Markers in Python
- Use contrasting colors for lines and markers.
- Keep markers large enough for presentations.
- Use gridlines to improve readability.
- Stick to simple dash styles for professional reports.
When I first started using Matplotlib in Python, I underestimated the power of small customizations like dashed lines and markers. Over time, I’ve found that these details can completely change how an audience interprets a chart.
By using the methods I shared above, you can create clean, professional, and engaging plots that clearly highlight your data.
If you experiment with different marker styles, dash patterns, and colors, you’ll quickly find a style that works best for your projects.
You may also read:
- Matplotlib subplots_adjust for Bottom and Right Margins
- Matplotlib Bar Chart Labels
- Matplotlib Save as PNG
- Matplotlib savefig Blank Image

I am Bijay Kumar, a Microsoft MVP in SharePoint. Apart from SharePoint, I started working on Python, Machine learning, and artificial intelligence for the last 5 years. During this time I got expertise in various Python libraries also like Tkinter, Pandas, NumPy, Turtle, Django, Matplotlib, Tensorflow, Scipy, Scikit-Learn, etc… for various clients in the United States, Canada, the United Kingdom, Australia, New Zealand, etc. Check out my profile.