Hey all! I'm looking to enhance my Matplotlib plots by adding a colored line or marker right next to my axis labels. This would help make it clearer which dataset corresponds to which axis, especially when I have multiple y-axes in a single plot. For example, I'd like the label to look like this:
`— Label`
where the `—` is a colored dash (like red) that matches the line color, while the text remains black. Any tips on how to achieve this would be super helpful!
2 Answers
You can add a marker next to your axis labels by customizing the labels directly. One way to do this is to use a combination of text and line elements. First, plot your data as usual and then use `ax.text()` to place a colored line next to the labels. You can adjust the position and color accordingly. Here’s a simple way to do it!
If you're looking to avoid legends, you might consider creating custom text annotations next to your axis labels. You can use `plt.annotate()` to place a colored marker right by the label as needed. That way, you keep everything contained without duplicating any info.

That makes sense! I guess it gives more control over the placement too. Thanks for this tip!