![]() ![]() It doesn't actually touch the value of the labels themselves (like the previous method), it just adjusts the formatting.In this method, you get a list of the labels, loop through each one, and set rotation and alignment for each. You can set the rotation property of the tick labels with this line: plt. This is a great method to know how to use but it's relatively verbose and comes with the caveat about needing to make sure the figure has been drawn before calling the get method. If you’re working with a single plot, you can use the () function to rotate the labels on the x-axis, pass the degree of rotation to the rotation parameter. That way, theyll take up less space horizontally and more space vertically. ![]() get_xticklabels (), rotation = 30, ha = 'right' ) In order to make the labels fit, were going to rotate the labels. Example 1: Rotate X-Axis Tick Labels The following code shows how to rotate the x-axis tick labels in Matplotlib: import matplotlib.pyplot as plt define data x 1, 2, 3, 4 y 7, 13, 24, 22 create plot plt.plot(x, y, color'red') rotate x-axis tick labels plt. get_xticklabels (), rotation = 30, ha = 'right' ) ax2. subplots ( 1, 2, figsize = ( 10, 5 )) ax1. MatPlotLib with Python DATAhill Solutions Srinivas Reddy To rotate tick labels in a. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |