Im setting up a cross sectional plot which illustrates dischargements at verticals; I'd like to annotate both the discharge and the unit, but I dont know how to add the unit to the plot inside of the zip-function.
more than happy about hints and suggestions :)
the input file looks as follows:
distance [m] depth [m] Q [l/s]
0 0.1 0.236 3.172
1 0.6 0.302 10.156
2 1.1 0.324 26.020
3 1.6 0.388 35.320
4 2.1 0.400 36.760
5 2.6 0.364 40.420
6 3.1 0.394 46.240
7 3.6 0.430 49.460
8 4.1 0.410 47.680
9 4.6 0.386 48.880
10 5.1 0.360 33.640
11 5.5 0.110 3.662
thats my current state:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
df=pd.read_csv(r'test.csv',sep=';')
#plot
x= df['distance [m]']
y= df['depth [m]']
Q= round(df['Q [l/s]'],2)
plt.gca().invert_yaxis()
plt.fill_between(x,y,0, color='skyblue')
#plt.plot(x,y,color='blue')
plt.xticks(np.arange(0, max(x)+0.5, 0.5))
plt.yticks(np.arange(round(min(y)), max(y)+0.1, 0.05))
plt.ylim()
ylab='waterdepth [m]'
xlab='distance to left river bank [m]'
title='discharge at river chainage X'
plt.ylabel(ylab)
plt.xlabel(xlab)
plt.title(title,weight='bold')
for xcoo,ycoo in zip(x,y):
plt.vlines(x=xcoo,ymin=0,ymax=ycoo,lw = 1,color='0.5',linestyles='dashed')
for xcoo,ycoo,q_test in zip(x,y,Q):
plt.annotate(q_test,xy=(xcoo,(ycoo/2)),color='red',weight='bold',ha='center',fontsize=7)
plt.annotate(q_test+' l/s', xy=..., ...) results in:
TypeError Traceback (most recent call last)
<ipython-input-59-bc9e0de80690> in <module>
22
23 for xcoo,ycoo,q_test in zip(x,y,Q):
---> 24 plt.annotate(q_test+'l/s',xy=(xcoo,(ycoo/2)),color='red',weight='bold',ha='center',fontsize=7)
25
26 #plt.savefig('test_plot.png',bbox_inches="tight", dpi = (300))
TypeError: unsupported operand type(s) for +: 'float' and 'str'

plt.annotate(q_test+' l/s', xy=..., ...)?plt.annotate(f'{q_test} l/s', xy=..., ...)?plt.annotate(str(q_test)+' l/s', xy=(Try this one and see.