Skip to content

[Bug]: Changing Linestyle in plot window swaps some plotted lines #22823

@lucashc

Description

@lucashc

Bug summary

After creating a figure with multiple lines plotted using the plt.loglog() command, altering the linestyle in the plot window under Figure Options -> Curves, results in some lines being swapped.

Code for reproduction

import matplotlib.pyplot as plt
import numpy as np

Ns = np.array([10, 20, 40, 80])
errors_fd = np.array([1.30069562e-17, 1.83972081e-17, 2.66824646e-16, 8.61976660e-16])
errors_dd = np.array([8.67886156e-12, 1.57381890e-11, 1.35584771e-08, 4.95264847e-06])
errors_operator = np.array([8.67888088e-12, 1.57381914e-11, 1.35584771e-08, 4.95264847e-06])
errors_rb = np.array([5.49503157e-06, 4.64897012e-06, 4.06345733e-06, 6.20409921e-06])


plt.loglog(Ns, errors_fd, label="Finite Difference", linestyle="-.", marker=".")
plt.loglog(Ns, errors_dd, label="Domain Decomposition", linestyle="-", marker="x")
plt.loglog(Ns, errors_operator, label="Exact Poincaré-Steklov", linestyle="-.", marker=".")
plt.loglog(Ns, errors_rb, label="Reduced Basis", linestyle="-.", marker=".")
plt.loglog(Ns, 1/Ns**2, label="Reference quadratic")
plt.xlabel("$N$ (number of disretisation points)")
plt.ylabel("$L^2$-error")
plt.grid()
plt.legend()
plt.title("$L^2$-error of numerical methods")

plt.show()

Actual outcome

Outcome plot:
image

After changing the linestyle of the "Domain Decomposition" line to dotted:
image

Expected outcome

I would expect that the "Finite Difference" line and the line of "Domain Decomposition" to not swap places in the graph.

Additional information

I have edited figures before and this is the first time this bug occurs for me.
I am on quite a new version of Python using the virtual environment provided by PyCharm Community Edition (Installed using Flatpak). I also run my code from within there.

Operating system

Fedora Workstation 35

Matplotlib Version

3.5.1

Matplotlib Backend

Backend QtAgg is interactive backend. Turning interactive mode on. Warning: Ignoring XDG_SESSION_TYPE=wayland on Gnome. Use QT_QPA_PLATFORM=wayland to run on Wayland anyway. Gtk-Message: 15:12:47.821: Failed to load module "canberra-gtk-module" Gtk-Message: 15:12:47.821: Failed to load module "pk-gtk-module" Gtk-Message: 15:12:47.821: Failed to load module "canberra-gtk-module" Gtk-Message: 15:12:47.822: Failed to load module "pk-gtk-module" QtAgg

Python version

Python 3.9.9

Jupyter version

Not installed

Installation

pip

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions