0

enter image description here

I have the plot above done out for a project I am currently working on. I am relatively new to matplotlib and want to ask would there be any way to connect the max point of each line to the y axis along the lines of something like this (except straight and not as poorly done :) ): enter image description here

M00N KNIGHT
  • 137
  • 1
  • 11
  • of course: you already have the last y values of every plotted line. And you get the minimum x value of the x axis via `plt.xlim()[0]` or `ax.get_xlim()[0]`. – SpghttCd Oct 18 '18 at 19:14
  • Thanks that may be useful in the future to know – M00N KNIGHT Oct 18 '18 at 19:23
  • See [this answer](https://stackoverflow.com/a/51536531/4124317), especially the last solution within on how to connect points defined in different coordinate systems with a line. – ImportanceOfBeingErnest Oct 18 '18 at 20:17

2 Answers2

1

example addressing the foreground issue of the hlines mentioned in the comments here.

plots visualizing the discussed variants:

enter image description here

created with this code:

data = [.82, .72, .6, .5, .45]
col = ['k', 'b', 'm', 'g', 'r']

fig, axs = plt.subplots(1, 3, figsize=(12, 4))

axs[0].set_title('Problem: hlines in foreround')
for d, c in zip(data, col):
    axs[0].plot([0, d], c, lw=10)
for d in data:
    axs[0].axhline(d, lw=5)

axs[1].set_title('Solution 1: zorder=0 for hlines')
for d, c in zip(data, col):
    axs[1].plot([0, d], c, lw=10)
for d in data:
    axs[1].axhline(d, lw=5, zorder=0)

axs[2].set_title('Solution 2: plot hlines first')
for d in data:
    axs[2].axhline(d, lw=5)
for d, c in zip(data, col):
    axs[2].plot([0, d], c, lw=10)

plt.tight_layout()
SpghttCd
  • 10,510
  • 2
  • 20
  • 25
0

So I found the following code allows me to draw these lines:

plt.axhline(y=0.8462, color='r', linestyle='--')

Which produces:

enter image description here

I can just repeat this for the other max values of y.

M00N KNIGHT
  • 137
  • 1
  • 11