Issue 1:
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:

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

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

Issue 2:
Bug summary

I am trying to plot stacked bar chart. I have already defined python dictionary mapping key to specific color. The problem I am getting is, color is not consistent while plotting the chart. when I do console print for same key, it shows correct color but chart shows different color. Also, height of the bar seems to be overlapped even having same number and kept it as "center".

Code for reproduction

import matplotlib.pyplot as plt
import random
import numpy as np
import matplotlib

random.seed(0)

FIG_SIZE = (50, 25)
FONT_SZ = 30

font = {'weight' : 'bold',
'size' : FONT_SZ}

matplotlib.rc('font', **font)

dict = {'AL': {'ALF': 1,
'CB': 1,
'CC': 2,
'HBBN': 6,
'N7': 6,
'PW': 2,
'PA': 4,
'PE': 3,
'PPC': 2,
'TI': 15},
'ALF': {'AL': 2,
'PE': 6,
'PET': 13},
'CB': {'N7': 1,
'PA': 16},
'CC': {'AE': 1,
'AL': 30,
'PW': 1,
'PA': 27,
'ST': 1},
'PW': {'AL': 33,
'ALF': 4,
'CC': 6,
'HBBC': 1,
'PA': 4,
'PC': 9,
'PE': 8,
'PET': 4,
'PWC': 8},
'PC': {'AL': 4,
'PW': 1,
'PA': 1,
'PWC': 1},
'PE': {'AL': 8,
'ALF': 3,
'HBBC': 1,
'HBBN': 2,
'N7': 2,
'PBC': 1,
'PWC': 12,
'PPL': 1},
'PPC': {'AL': 14,
'CC': 7,
'PA': 1},
'PPB': {'N7': 6,
'PC': 3,
'ST': 6},
'TE': {'AL': 20,
'CC': 46,
'PA': 3,
'PE': 1},
'TI': {'AL': 101,
'CC': 2,
'HC': 1,
'N7': 2,
'PW': 2,
'PA': 5,
'PC': 6,
'PWC': 2,
'PPC': 4,
'PPL': 4}}

colors = [
'AliceBlue', 'Chartreuse', 'Aqua', 'Aquamarine', 'Azure', 'Beige', 'Bisque',
'BlanchedAlmond', 'BlueViolet', 'BurlyWood', 'CadetBlue', 'AntiqueWhite'
]

klass_names = dict.keys()

random.shuffle(colors)

klass_color_dict = {}
legend_dict = {}

fig, ax = plt.subplots(figsize=FIG_SIZE)

for klass in klass_names:
col = random.choice(colors)
while col in klass_color_dict.values():
col = random.choice(colors)
klass_color_dict[klass] = col

for klass in klass_names:
for subklass in dict[klass].keys():
color = klass_color_dict.get(subklass)
label=subklass
if legend_dict.get(label, 0) == 0:
legend_dict[label] = 1
else:
label = ""
p1 = ax.bar(x=klass, height=dict[klass][subklass], color=color, label=label)
ax.bar_label(p1, label_type='center')
print(klass, subklass, color)

plt.savefig("plt.jpeg")

Actual outcome

As seen above, TE bar has same color even keys are different and it's not consistent.

Expected outcome

color values should be consistent.

Additional information

Python docker image is used.

Operating system

Ubuntu 18.04

Matplotlib Version

3.6

Matplotlib Backend

agg

Python version

3.10.7

Jupyter version

No response

Installation

No response