Untitled

mail@pastecode.io avatar
unknown
plain_text
14 days ago
1.3 kB
2
Indexable
Never
import matplotlib.pyplot as plt
from matplotlib.dates import DateFormatter, DayLocator
from datetime import datetime

dates = [datetime(2024, 6, 26), datetime(2024, 6, 27), datetime(2024, 6, 28), datetime(2024, 6, 29)]
prices_open = [100, 105, 98, 108]
prices_high = [108, 112, 108, 111]
prices_low = [98, 103, 94, 99]
price_close = [105, 110, 100, 100]

fig, ax = plt.subplots(figsize=(10, 6))

for i in range(len(dates)):
    date = dates[i]
    open_price = prices_open[i]
    high_price = prices_high[i]
    low_price = prices_low[i]
    close_price = price_close[i]
    
    # Plot high-low line
    ax.plot([date, date], [low_price, high_price], color='black', linewidth=1)
    
    # Plot open-close bar
    if open_price > close_price:
        ax.bar(date, open_price - close_price, bottom=close_price, width=0.8, align='center', color='red', edgecolor='black')
    else:
        ax.bar(date, close_price - open_price, bottom=open_price, width=0.8, align='center', color='green', edgecolor='black')

ax.xaxis.set_major_locator(DayLocator())
ax.xaxis.set_major_formatter(DateFormatter('%Y-%m-%d'))
ax.set_xlabel('Data e muajit')
ax.set_ylabel('Vlera Euro/Lek')
ax.set_title('Kembimi valutor')
plt.tight_layout()
plt.show()
Leave a Comment