Repository navigation
Description
This is related to #8040 and #9797, possibly #7219.
Bug report
Apart from strings like "-", "--", ":" , the linestyle can also be set as a tuple of an on/off sequence. There are however two different notations,
(on, off, on, off, ...)and(start, (on, off, on, off, ...)).
For all of the ways to set the linestyle, only one or none of those actually work.
Most importantly there is currently no way to set an on/off linestyle via the rc file.
The following lists those combinations and whether they work or not with the respective commands.
linestyle /dashes inside plot function
| command | working |
|---|---|
plt.plot([1,2], linestyle=":") |
✔️ |
plt.plot([1,2], linestyle=(5,1,1,1)) |
❌ |
plt.plot([1,2], linestyle=(0,(5,1,1,1))) |
✔️ |
plt.plot([1,2], dashes=":") |
❌ |
plt.plot([1,2], dashes=(5,1,1,1)) |
✔️ |
plt.plot([1,2], dashes=(0, (5,1,1,1))) |
❌ |
using rcParams
| command | working |
|---|---|
plt.rcParams["grid.linestyle"] = ":" |
✔️ |
plt.rcParams["grid.linestyle"] = (5,1,1,1) |
✔️ |
plt.rcParams["grid.linestyle"] = (0,(5,1,1,1)) |
❌ |
inside cycler using rcParams
| command | working |
|---|---|
plt.rcParams["axes.prop_cycle"] += plt.cycler("linestyle", [":"]) |
✔️ |
plt.rcParams["axes.prop_cycle"] += plt.cycler("linestyle", [(5,1,1,1)]) |
❌ |
plt.rcParams["axes.prop_cycle"] += plt.cycler("linestyle", [(0,(5,1,1,1))]) |
✔️ |
using rc file
| command | working |
|---|---|
grid.linestyle : : |
✔️ |
grid.linestyle : (5,1,1,1) |
❌ |
grid.linestyle : (0,(5,1,1,1)) |
❌ |
inside cycler using rc file
| command | working |
|---|---|
axes.prop_cycle : cycler("linestyle", [":"] ) |
✔️ |
axes.prop_cycle : cycler("linestyle", [(5,1,1,1)] ) |
❌ |
axes.prop_cycle : cycler("linestyle", [(0,(5,1,1,1))] ) |
❌ |
Correlation
| command | string ":" |
tuple (5,1,1,1) |
tuple (0,(5,1,1,1)) |
|---|---|---|---|
plt.plot(..., linestyle=x) |
✔️ | ❌ | ✔️ |
plt.plot(..., dashes=x) |
❌ | ✔️ | ❌ |
plt.rcParams["grid.linestyle"] = x |
✔️ | ✔️ | ❌ |
plt.rcParams["axes.prop_cycle"] += plt.cycler("linestyle", [x]) |
✔️ | ❌ | ✔️ |
rc file grid.linestyle : x |
✔️ | ❌ | ❌ |
rc file axes.prop_cycle : cycler("linestyle", [x] ) |
✔️ | ❌ | ❌ |
I think the first thing to do here is to identify which combinations should actually work.
attn. @afvincent who has last worked on validation of linestyle rc Parameters.
Activity
anntzer commentedon Jan 21, 2020
Many cases (not all) were fixed by #15827.
1 remaining item
github-actions commentedon Aug 16, 2024
This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!
timhoffm commentedon Aug 21, 2024
To move forward or close this, it would be good to recreate the initial tables on what works and what not with the current version of matplotlib.
I'm marking this as good first issue for recreating the tables. Further actions will need to be discussed on the result.
github-actions commentedon Aug 21, 2024
Good first issue - notes for new contributors
This issue is suited to new contributors because it does not require understanding of the
Matplotlib internals. To get started, please see our contributing
guide.
We do not assign issues. Check the Development section in the sidebar for linked pull
requests (PRs). If there are none, feel free to start working on it. If there is an open PR, please
collaborate on the work by reviewing it rather than duplicating it in a competing PR.
If something is unclear, please reach out on any of our communication
channels.
timhoffm commentedon Aug 21, 2024
As good first issue: It would be good to recreate the initial tables on what works and what not with the current version of matplotlib.
QuLogic commentedon Aug 31, 2024
I thought @oscargus looked into this wrt dashes and linestyles?
saumyacoder1709 commentedon Jan 1, 2026
I would like to work on this issue. Can somebody guide me what it needs?
timhoffm commentedon Jan 2, 2026
@saumyacoder1709 start with #11797 (comment)
As a general remark, we don't have the capacity to guide. We expect contributors to be able to understand and reproduce the issue, and come up with a reasonable solution suggestion based on the given information. Please be sure to have read and undstood our contribution guildelines and the complete issue thread.
maederan201 commentedon Jan 28, 2026
Hello,
I recreated the tables as requested above using the current matplotlib version, here's the overview:
linestyle/dashed inside plot function
plt.plot([1,2], linestyle=":")plt.plot([1,2], linestyle=(5,1,1,1))plt.plot([1,2], linestyle=(0,(5,1,1,1)))plt.plot([1,2], dashes=":")plt.plot([1,2], dashes=(5,1,1,1))plt.plot([1,2], dashes=(0, (5,1,1,1)))using rcParams
plt.rcParams["grid.linestyle"] = ":"plt.rcParams["grid.linestyle"] = (5,1,1,1)plt.rcParams["grid.linestyle"] = (0,(5,1,1,1))inside cycler using rcParams
plt.rcParams["axes.prop_cycle"] += plt.cycler("linestyle", [":"])plt.rcParams["axes.prop_cycle"] += plt.cycler("linestyle", [(5,1,1,1)])plt.rcParams["axes.prop_cycle"] += plt.cycler("linestyle", [(0,(5,1,1,1))])using rc file
grid.linestyle : :grid.linestyle : (5,1,1,1)grid.linestyle : (0,(5,1,1,1))inside cycler using rc file
axes.prop_cycle : cycler("linestyle", [":"] )axes.prop_cycle : cycler("linestyle", [(5,1,1,1)] )axes.prop_cycle : cycler("linestyle", [(0,(5,1,1,1))] )From a quick glance over the missing ones, it seems some adjustments in lines.py are required. I will try and make those and produce a PR.
maederan201 commentedon Jan 28, 2026
Creating a fix such that the commands above all work was sufficiently easy, however this raised some other issues.
Am I correct in assuming that the
(offset, (on, off, on, off, ...))way of setting dashes is the one that should be used in the backend everywhere?In that case it is just a case of translating single tuples and strings like
":"to have offset 0.