why am I only getting the tick mark for 0 and 10 with this code: def…
- User
why am I only getting the tick mark for 0 and 10 with this code: def plot_losses_test(numberEpochs, losses, learning_rate): epochs = list(range(numberEpochs))
plt.figure(figsize=(10, 5)) plt.plot(epochs, losses, marker='o', linestyle='-', color='g', label='Loss') plt.title(f'Loss Over {numberEpochs} Epochs with Learning Rate of {learning_rate}') plt.xlabel('Epoch') plt.ylabel('Loss') plt.xticks(np.arange(0, numberEpochs / 10, 10)) plt.grid(False) plt.legend() plt.tight_layout() plt.show()
- Assistant
The issue with your
xtickssetting is that you are usingnp.arangeincorrectly given your goal. Thenp.arangefunction generates a range of values but the parameters you are using do not achieve the desired result.In your code, you're calling
np.arange(0, numberEpochs / 10, 10), which means you are starting at0, ending atnumberEpochs / 10, and stepping by10. This will only produce tick marks at0and possibly10ifnumberEpochs / 10is greater than10.Here's how to rectify the code:
-
If you want tick marks at every 10 epochs, use instead. This way, it starts at , goes up to (inclusive), and steps every epochs.
-
- User
how to add subtitle to graph in matplotlib
- Assistant
In Matplotlib, you can add a subtitle to a graph using the
plt.suptitle()function or by using theax.set_title()method for specific axes. Here's how to do both: