“Subplot dalam untuk loop python (tidak ada dinamis)” Kode Jawaban

Subplot dalam untuk loop python (tidak ada dinamis)

plt.figure(figsize=(15, 12))
plt.subplots_adjust(hspace=0.5)
plt.suptitle("Daily closing prices", fontsize=18, y=0.95)

# loop through the length of tickers and keep track of index
for n, ticker in enumerate(tickers):
    # add a new subplot iteratively
    ax = plt.subplot(3, 2, n + 1)

    # filter df and plot ticker on the new subplot axis
    df[df["ticker"] == ticker].plot(ax=ax)

    # chart formatting
    ax.set_title(ticker.upper())
    ax.get_legend().remove()
    ax.set_xlabel("")
Cdev2

Subplot dalam untuk loop python (tidak ada dinamis)

# define subplot grid
fig, axs = plt.subplots(nrows=3, ncols=2, figsize=(15, 12))
plt.subplots_adjust(hspace=0.5)
fig.suptitle("Daily closing prices", fontsize=18, y=0.95)

# loop through tickers and axes
for ticker, ax in zip(tickers, axs.ravel()):
    # filter df for ticker and plot on specified axes
    df[df["ticker"] == ticker].plot(ax=ax)

    # chart formatting
    ax.set_title(ticker.upper())
    ax.get_legend().remove()
    ax.set_xlabel("")

plt.show()
Cdev2

Jawaban yang mirip dengan “Subplot dalam untuk loop python (tidak ada dinamis)”

Pertanyaan yang mirip dengan “Subplot dalam untuk loop python (tidak ada dinamis)”

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya