Black Lives Matter. Please consider donating to Black Girls Code today.
Dash HoloViews is now available! Check out the docs.

Interactive Bar Chart where user can select which columns to view

I have a bar chart with 27 subplots that I created in matplotlib with Pandas. I’m wondering if there is a way in Plotly to create buttons for each political party so that the user can select which parties specifically they want to view in all of the subplots. So for example, the user clicks the ‘DEM’ button and the ‘REP’ button and only the DEM and REP columns show. I was thinking of doing this because the WEP and REF parties w/r/t voter registration percent change overwhelm the other parties, so I was thinking it would be neat if the user could select the parties they want to view. Below is my code:

fig, axes = plt.subplots(9,3,figsize=(50,80), sharey=True)
fig.suptitle("Percentage Change of Voter Registration by Party in all 27 Congressional Districts of New York", fontsize=40)
fig.subplots_adjust(top=0.96)

ax = axes.flatten()
ax1 = district_1_change.drop(['TOTAL'], axis=1).plot.bar(legend=True, ax=ax[0], color=['xkcd:blue', 'xkcd:red', 'xkcd:dark red', 'xkcd:light blue', 'xkcd:purple',         'xkcd:green', 'xkcd:orange', 'xkcd:brown','xkcd:pink', 'xkcd:lilac']) 
ax1.set_title("District 1 (R): Eastern Long Island", fontsize=30) 
ax2 = district_2_change.drop(['TOTAL'], axis=1).plot.bar(legend=True, ax=ax[1], color=['xkcd:blue', 'xkcd:red', 'xkcd:dark red', 'xkcd:light blue', 'xkcd:purple',         'xkcd:green', 'xkcd:orange', 'xkcd:brown','xkcd:pink', 'xkcd:lilac']) 
ax2.set_title("District 2(R): Southern Long Island", fontsize=30) 
ax3 = district_3_change.drop(['TOTAL'], axis=1).plot.bar(legend=True, ax=ax[2], color=['xkcd:blue', 'xkcd:red', 'xkcd:dark red', 'xkcd:light blue', 'xkcd:purple',         'xkcd:green', 'xkcd:orange', 'xkcd:brown','xkcd:pink', 'xkcd:lilac']) 
ax3.set_title("District 3(D): Northern Long Island", fontsize=30) 
ax4 = district_4_change.drop(['TOTAL'], axis=1).plot.bar(legend=True, ax=ax[3], color=['xkcd:blue', 'xkcd:red', 'xkcd:dark red', 'xkcd:light blue', 'xkcd:purple',         'xkcd:green', 'xkcd:orange', 'xkcd:brown','xkcd:pink', 'xkcd:lilac']) 
ax4.set_title("District 4(D): Central, Southern Nassau County", fontsize=30) 
ax5 = district_5_change.drop(['TOTAL'], axis=1).plot.bar(legend=True, ax=ax[4], color=['xkcd:blue', 'xkcd:red', 'xkcd:dark red', 'xkcd:light blue', 'xkcd:purple',         'xkcd:green', 'xkcd:orange', 'xkcd:brown','xkcd:pink', 'xkcd:lilac']) 
ax5.set_title("District 5(D): Queens", fontsize=30) 
ax6 = district_6_change.drop(['TOTAL'], axis=1).plot.bar(legend=True, ax=ax[5], color=['xkcd:blue', 'xkcd:red', 'xkcd:dark red', 'xkcd:light blue', 'xkcd:purple',         'xkcd:green', 'xkcd:orange', 'xkcd:brown','xkcd:pink', 'xkcd:lilac']) 
ax6.set_title("District 6(D): Queens", fontsize=30) 
ax7 = district_7_change.drop(['TOTAL'], axis=1).plot.bar(legend=True, ax=ax[6], color=['xkcd:blue', 'xkcd:red', 'xkcd:dark red', 'xkcd:light blue', 'xkcd:purple',         'xkcd:green', 'xkcd:orange', 'xkcd:brown','xkcd:pink', 'xkcd:lilac']) 
ax7.set_title("District 7(D): Queens", fontsize=30) 
ax8 = district_8_change.drop(['TOTAL'], axis=1).plot.bar(legend=True, ax=ax[7], color=['xkcd:blue', 'xkcd:red', 'xkcd:dark red', 'xkcd:light blue', 'xkcd:purple',         'xkcd:green', 'xkcd:orange', 'xkcd:brown','xkcd:pink', 'xkcd:lilac']) 
ax8.set_title("District 8(D): Brooklyn, Queens", fontsize=30) 
ax9 = district_9_change.drop(['TOTAL'], axis=1).plot.bar(legend=True, ax=ax[8], color=['xkcd:blue', 'xkcd:red', 'xkcd:dark red', 'xkcd:light blue', 'xkcd:purple',         'xkcd:green', 'xkcd:orange', 'xkcd:brown','xkcd:pink', 'xkcd:lilac']) 
ax9.set_title("District 9(D): Brooklyn", fontsize=30) 
ax10 = district_10_change.drop(['TOTAL'], axis=1).plot.bar(legend=True, ax=ax[9], color=['xkcd:blue', 'xkcd:red', 'xkcd:dark red', 'xkcd:light blue', 'xkcd:purple',         'xkcd:green', 'xkcd:orange', 'xkcd:brown','xkcd:pink', 'xkcd:lilac']) 
ax10.set_title("District 10(D): Upper West Side, FiDi, Greenwich Village, Borough Park (BK)", fontsize=30) 
ax11 = district_11_change.drop(['TOTAL'], axis=1).plot.bar(legend=True, ax=ax[10], color=['xkcd:blue', 'xkcd:red', 'xkcd:dark red', 'xkcd:light blue', 'xkcd:purple',         'xkcd:green', 'xkcd:orange', 'xkcd:brown','xkcd:pink', 'xkcd:lilac']) 
ax11.set_title("District 11(R): Staten Island, Southern Brooklyn", fontsize=30) 
ax12 = district_12_change.drop(['TOTAL'], axis=1).plot.bar(legend=True, ax=ax[11], color=['xkcd:blue', 'xkcd:red', 'xkcd:dark red', 'xkcd:light blue', 'xkcd:purple',         'xkcd:green', 'xkcd:orange', 'xkcd:brown','xkcd:pink', 'xkcd:lilac']) 
ax12.set_title("District 12(D): Eastern Manhattan, Greenpoint (BK), Western Queens", fontsize=30) 
ax13 = district_13_change.drop(['TOTAL'], axis=1).plot.bar(legend=True, ax=ax[12], color=['xkcd:blue', 'xkcd:red', 'xkcd:dark red', 'xkcd:light blue', 'xkcd:purple',         'xkcd:green', 'xkcd:orange', 'xkcd:brown','xkcd:pink', 'xkcd:lilac']) 
ax13.set_title("District 13(D): Upper Manhattan, Bronx", fontsize=30) 
ax14 = district_14_change.drop(['TOTAL'], axis=1).plot.bar(legend=True, ax=ax[13], color=['xkcd:blue', 'xkcd:red', 'xkcd:dark red', 'xkcd:light blue', 'xkcd:purple',         'xkcd:green', 'xkcd:orange', 'xkcd:brown','xkcd:pink', 'xkcd:lilac']) 
ax14.set_title("District 14(D): Eastern Bronx, North Central Queens", fontsize=30) 
ax15 = district_15_change.drop(['TOTAL'], axis=1).plot.bar(legend=True, ax=ax[14], color=['xkcd:blue', 'xkcd:red', 'xkcd:dark red', 'xkcd:light blue', 'xkcd:purple',         'xkcd:green', 'xkcd:orange', 'xkcd:brown','xkcd:pink', 'xkcd:lilac']) 
ax15.set_title("District 15(D): Southern, Western Bronx", fontsize=30) 
ax16 = district_16_change.drop(['TOTAL'], axis=1).plot.bar(legend=True, ax=ax[15], color=['xkcd:blue', 'xkcd:red', 'xkcd:dark red', 'xkcd:light blue', 'xkcd:purple',         'xkcd:green', 'xkcd:orange', 'xkcd:brown','xkcd:pink', 'xkcd:lilac']) 
ax16.set_title("District 16(D): North Bronx, Southern Westchester ", fontsize=30) 
ax17 = district_17_change.drop(['TOTAL'], axis=1).plot.bar(legend=True, ax=ax[16], color=['xkcd:blue', 'xkcd:red', 'xkcd:dark red', 'xkcd:light blue', 'xkcd:purple',         'xkcd:green', 'xkcd:orange', 'xkcd:brown','xkcd:pink', 'xkcd:lilac']) 
ax17.set_title("District 17(D): Rockland, Westchester", fontsize=30) 
ax18 = district_18_change.drop(['TOTAL'], axis=1).plot.bar(legend=True, ax=ax[17], color=['xkcd:blue', 'xkcd:red', 'xkcd:dark red', 'xkcd:light blue', 'xkcd:purple',         'xkcd:green', 'xkcd:orange', 'xkcd:brown','xkcd:pink', 'xkcd:lilac']) 
ax18.set_title("District 18(D): Orange, Putnam, Southern Dutchess, Northeastern Westchester", fontsize=30) 
ax19 = district_19_change.drop(['TOTAL'], axis=1).plot.bar(legend=True, ax=ax[18], color=['xkcd:blue', 'xkcd:red', 'xkcd:dark red', 'xkcd:light blue', 'xkcd:purple',         'xkcd:green', 'xkcd:orange', 'xkcd:brown','xkcd:pink', 'xkcd:lilac']) 
ax19.set_title("District 19(R): Hudson Valley, Catskills", fontsize=30) 
ax20 = district_20_change.drop(['TOTAL'], axis=1).plot.bar(legend=True, ax=ax[19], color=['xkcd:blue', 'xkcd:red', 'xkcd:dark red', 'xkcd:light blue', 'xkcd:purple',         'xkcd:green', 'xkcd:orange', 'xkcd:brown','xkcd:pink', 'xkcd:lilac']) 
ax20.set_title("District 20(D): Albany, Schenectady", fontsize=30) 
ax21 = district_21_change.drop(['TOTAL'], axis=1).plot.bar(legend=True, ax=ax[20], color=['xkcd:blue', 'xkcd:red', 'xkcd:dark red', 'xkcd:light blue', 'xkcd:purple',         'xkcd:green', 'xkcd:orange', 'xkcd:brown','xkcd:pink', 'xkcd:lilac']) 
ax21.set_title("""District 21(R): Clinton, Essex, Franklin, Fulton, Hamilton, Herkimer, 
               Jefferson, Lewis, Saratoga, St. Lawrence, Warren, and Washington""", fontsize=30) 
ax22 = district_22_change.drop(['TOTAL'], axis=1).plot.bar(legend=True, ax=ax[21], color=['xkcd:blue', 'xkcd:red', 'xkcd:dark red', 'xkcd:light blue', 'xkcd:purple',         'xkcd:green', 'xkcd:orange', 'xkcd:brown','xkcd:pink', 'xkcd:lilac']) 
ax22.set_title("District 22(R): Central New York", fontsize=30) 
ax23 = district_23_change.drop(['TOTAL'], axis=1).plot.bar(legend=True, ax=ax[22], color=['xkcd:blue', 'xkcd:red', 'xkcd:dark red', 'xkcd:light blue', 'xkcd:purple',         'xkcd:green', 'xkcd:orange', 'xkcd:brown','xkcd:pink', 'xkcd:lilac']) 
ax23.set_title("District 23(R): Western New York", fontsize=30) 
ax24 = district_24_change.drop(['TOTAL'], axis=1).plot.bar(legend=True, ax=ax[23], color=['xkcd:blue', 'xkcd:red', 'xkcd:dark red', 'xkcd:light blue', 'xkcd:purple',         'xkcd:green', 'xkcd:orange', 'xkcd:brown','xkcd:pink', 'xkcd:lilac']) 
ax24.set_title("District 24(R): Cayuga, Onondaga, Wayne, Western Oswego", fontsize=30) 
ax25 = district_25_change.drop(['TOTAL'], axis=1).plot.bar(legend=True, ax=ax[24], color=['xkcd:blue', 'xkcd:red', 'xkcd:dark red', 'xkcd:light blue', 'xkcd:purple',         'xkcd:green', 'xkcd:orange', 'xkcd:brown','xkcd:pink', 'xkcd:lilac']) 
ax25.set_title("District 25: Monroe", fontsize=30) 
ax26 = district_26_change.drop(['TOTAL'], axis=1).plot.bar(legend=True, ax=ax[25], color=['xkcd:blue', 'xkcd:red', 'xkcd:dark red', 'xkcd:light blue', 'xkcd:purple',         'xkcd:green', 'xkcd:orange', 'xkcd:brown','xkcd:pink', 'xkcd:lilac']) 
ax26.set_title("District 26(D): Western New York: Erie, Niagara", fontsize=30) 
ax27 = district_27_change.drop(['TOTAL'], axis=1).plot.bar(legend=True, ax=ax[26], color=['xkcd:blue', 'xkcd:red', 'xkcd:dark red', 'xkcd:light blue', 'xkcd:purple',         'xkcd:green', 'xkcd:orange', 'xkcd:brown','xkcd:pink', 'xkcd:lilac']) 
ax27.set_title("District 27(R): Western New York", fontsize=30);