Customizing Y-Axis Limits in Matplotlib
In matplotlib, customizing the axis limits is crucial for presenting data effectively. This question addresses the need to set the y-axis limits for a specific plot, where the provided code fails to achieve the desired limits.
To address this issue, we can use the following approach:
ax = plt.gca()
ax.set_ylim([ymin, ymax])
In the example provided in the question, the code can be modified as follows:
import matplotlib.pyplot as plt plt.figure(1, figsize = (8.5,11)) plt.suptitle('plot title') ax = [] aPlot = plt.subplot(321, axisbg = 'w', title = "Year 1") ax.append(aPlot) plt.plot(paramValues,plotDataPrice[0], color = '#340B8C', marker = 'o', ms = 5, mfc = '#EB1717') plt.xticks(paramValues) plt.ylabel('Average Price') plt.xlabel('Mark-up') plt.grid(True) # Set y-axis limits ax = plt.gca() ax.set_ylim([20, 250])
With this adjustment, the y-axis limits will be set to [20, 250], as desired.
The above is the detailed content of How to Customize Y-Axis Limits in Matplotlib Plots?. For more information, please follow other related articles on the PHP Chinese website!