From tcaswell at gmail.com Wed Mar 9 20:35:40 2022 From: tcaswell at gmail.com (Thomas Caswell) Date: Wed, 9 Mar 2022 20:35:40 -0500 Subject: [Matplotlib-users] Report a possible colorbar extend bug In-Reply-To: References: Message-ID: Haoyu, Please subscribe to the mailing list to post unmoderated. This looks like a real bug to me, please report this as an issue on github ( https://github.com/matplotlib/matplotlib/issues/new/choose)? Tom On Wed, Mar 9, 2022 at 6:59 PM Haoyu Yang wrote: > Dear Matplotlib team, > > > > I hope this letter finds you well. > > > > I?m a new matplotlib so I?m not sure if it?s me doing wrong or there could > be a bug replated to matplotlib itself. I?m currently running Python 3.10 > with Matplotlib 3.5.1. This possible bug seems to be related to some > incompatibility between the ?extend? argument in ?plt.figure.colorbar? and > ?.ax.invert_yaxis()? functions. More specifically, if I just extend the max > of colorbar (first figure) or just invert the y-axis of the colorbar(second > figure), everything work fine. However, if I do this two at the same time, > the colorbar would be inverted while the extended arrow is not(figure > three). > > > > > > > > And I here enclosed the code which I use to create the plot: > > # Generate X/Y point mesh grid > > x = np.linspace(-4.5, 1.5, 400) > > y = np.linspace(-8, -2, 400) > > X, Y = np.meshgrid(x, y) > > potential, rate_determining_step = > calculate_limiting_potential_from_linear_relations(X, Y, > free_energy_dict)[0], calculate_limiting_potential_from_linear_relations(X, > Y, free_energy_dict)[1] # calculate limiting potential for each point on > the mesh grid > > > > # Create backup ground volcano plot > > fig = plt.figure(figsize=[8, 6]) > > background = fig.add_subplot(111) # add sub plot > > > > # Add contour plot > > contour = background.contourf(X, Y, potential, levels=512, > cmap="rainbow") # create filled contour (reverse rainbow) > > > > # Create colorbar > > cbar = fig.colorbar(contour, shrink=0.95, aspect=15, ticks=[1, 2, 3, > 4]) # create colorbar (shrink/aspect for the size of the bar) > > cbar.set_label("Limiting Potential (eV)", fontsize=16) # add label to > the colorbar > > cbar.ax.tick_params(labelsize=12) # set tick label size > > cbar.ax.invert_yaxis() # put the colorbar upside down > > > > Sorry I can?t send you the script and datasheet because it contents > sensitive data. Thanks for your time and wishing you all the best. > > > > Regards, > > Haoyu > _______________________________________________ > Matplotlib-users mailing list > Matplotlib-users at python.org > https://mail.python.org/mailman/listinfo/matplotlib-users > -- Thomas Caswell tcaswell at gmail.com -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: image002.png Type: image/png Size: 110408 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: image003.png Type: image/png Size: 108221 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: image005.png Type: image/png Size: 130972 bytes Desc: not available URL: From efiring at hawaii.edu Wed Mar 9 20:41:39 2022 From: efiring at hawaii.edu (Eric Firing) Date: Wed, 9 Mar 2022 15:41:39 -1000 Subject: [Matplotlib-users] Report a possible colorbar extend bug In-Reply-To: References: Message-ID: <984201c8-9063-4cfa-5fd3-30200fb3c2e7@hawaii.edu> You are right, there is a problem, in that something that looks like it should work, doesn't work as reasonably expected. It is already an open issue: https://github.com/matplotlib/matplotlib/issues/22052 Eric On 2022/02/26 1:30 AM, Haoyu Yang wrote: > Dear Matplotlib team, > > I hope this letter finds you well. > > I?m a new matplotlib so I?m not sure if it?s me doing wrong or there > could be a bug replated to matplotlib itself. I?m currently running > Python 3.10 with Matplotlib 3.5.1. This possible bug seems to be related > to some incompatibility between the ?extend? argument in > ?plt.figure.colorbar? and ?.ax.invert_yaxis()? functions. More > specifically, if I just extend the max of colorbar (first figure) or > just invert the y-axis of the colorbar(second figure), everything work > fine. However, if I do this two at the same time, the colorbar would be > inverted while the extended arrow is not(figure three). > > And I here enclosed the code which I use to create the plot: > > # Generate X/Y point mesh grid > > ??? x = np.linspace(-4.5, 1.5, 400) > > ????y = np.linspace(-8, -2, 400) > > ??? X, Y = np.meshgrid(x, y) > > ??? potential, rate_determining_step = > calculate_limiting_potential_from_linear_relations(X, Y, > free_energy_dict)[0], > calculate_limiting_potential_from_linear_relations(X, Y, > free_energy_dict)[1]?? # calculate limiting potential for each point on > the mesh grid > > ??? # Create backup ground volcano plot > > ??? fig = plt.figure(figsize=[8, 6]) > > ??? background = fig.add_subplot(111)? # add sub plot > > ??? # Add contour plot > > contour = background.contourf(X, Y, potential, levels=512, > cmap="rainbow")? # create filled contour (reverse rainbow) > > ??? # Create colorbar > > ??? cbar = fig.colorbar(contour, shrink=0.95, aspect=15, ticks=[1, 2, > 3, 4])? # create colorbar (shrink/aspect for the size of the bar) > > ??? cbar.set_label("Limiting Potential (eV)", fontsize=16)? # add label > to the colorbar > > ??? cbar.ax.tick_params(labelsize=12)? # set tick label size > > ??? cbar.ax.invert_yaxis()? # put the colorbar upside down > > Sorry I can?t ?send you the script and datasheet because it contents > sensitive data. Thanks for your time and wishing you all the best. > > Regards, > > Haoyu > > > _______________________________________________ > Matplotlib-users mailing list > Matplotlib-users at python.org > https://mail.python.org/mailman/listinfo/matplotlib-users