How to auto align x-axis label - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: How to auto align x-axis label (/thread-39296.html) |
How to auto align x-axis label - SamLiu - Jan-27-2023 Hi all, A matplotlib plt.bar demo create a chart as snapshots, how to set up x-axis label no shadow,thanks!! import matplotlib.pyplot as plt plt.style.use('ggplot') labels = ['MEMS Vbias', 'AVDD Continuity', 'DVDD Continuity', 'IIL CLK', 'Ref Sens ADC Gain Final', 'YL_gest_NM','Y1_HSPL_LPM_offset_trim', 'Current_fail', 'Out of Range'] values = [10, 15, 12, 9, 7, 13, 1, 1, 1] fig = plt.figure(figsize=(10, 5)) # creating the bar plot plt.bar(labels, values, color=['black','red','green','blue','cyan',]) plt.ylabel("Failed_QTY") plt.title("Tester Failed overview") plt.show() RE: How to auto align x-axis label - deanhystad - Jan-27-2023 What's the problem? You made the chart too small for the long labels. You can: 1 Make the chart bigger 2 User shorter labels 3 Specify a smaller font for the labels 4 Rotate the labels You could do this to the labels: labels = [ "MEMS\nVbias", "AVDD\nContinuity", "DVDD\nContinuity", "IIL\nCLK", "Ref Sens\nADC Gain\nFinal", "YL_gest_NM", "Y1_HSPL\nLPM_noffset\ntrim", "Current\nfail", "Out of\nRange",Or rotate the labels. import matplotlib.pyplot as plt plt.style.use("ggplot") labels = [ "MEMS Vbias", "AVDD Continuity", "DVDD Continuity", "IIL CLK", "Ref Sens ADC Gain Final", "YL_gest_NM", "Y1_HSPL_LPM_offset_trim", "Current_fail", "Out of Range", ] values = [10, 15, 12, 9, 7, 13, 1, 1, 1] fig = plt.figure(figsize=(10, 5)) # creating the bar plot plt.bar( labels, values, color=[ "black", "red", "green", "blue", "cyan", ], ) plt.ylabel("Failed_QTY") plt.title("Tester Failed overview") plt.xticks(rotation=45) plt.tight_layout() plt.show()My preference is shorter labels. Do you really need "Ref Sens ADC Gain Final" instead of "Reference\nGain". Can you replace "Y1_HSPL_LPM_offset_trim" with shorter gobbledygook? RE: How to auto align x-axis label - SamLiu - Jan-27-2023 (Jan-27-2023, 04:29 PM)deanhystad Wrote: What's the problem? You made the chart too small for the long labels. You can: I appreciated you that is what I want, thanks!! |