From: Daniele N. <da...@gr...> - 2013-10-28 22:19:55
|
Hello, I'm trying to change the font size for the tick labels. I've tried both setting it explicitly when creating the labels: ax2.set_xticklabel(['%d' % x for x in arange(10)], fontsize=10) or after: for label in ax2.get_xticklabels(): label.set_fontsize(8) but the rendering is unaffected by the setting. This is with the MacOSX backend and with the PDF backend. Is it a bug or am I missing something? Thanks. Best, Daniele |
From: Oliver <oli...@gm...> - 2013-10-28 22:30:42
|
Hi Daniele, not sure, but it seems to work for me. Did you do a plt.draw() or plt.show() to reflect the changes? Kind regards, Oliver 2013/10/28 Daniele Nicolodi <da...@gr...> > Hello, > > I'm trying to change the font size for the tick labels. I've tried both > setting it explicitly when creating the labels: > > ax2.set_xticklabel(['%d' % x for x in arange(10)], fontsize=10) > > or after: > > for label in ax2.get_xticklabels(): > label.set_fontsize(8) > > but the rendering is unaffected by the setting. This is with the MacOSX > backend and with the PDF backend. Is it a bug or am I missing something? > > Thanks. Best, > Daniele > > > ------------------------------------------------------------------------------ > Android is increasing in popularity, but the open development platform that > developers love is also attractive to malware creators. Download this white > paper to learn more about secure code signing practices that can help keep > Android apps secure. > http://pubads.g.doubleclick.net/gampad/clk?id=65839951&iu=/4140/ostg.clktrk > _______________________________________________ > Matplotlib-users mailing list > Mat...@li... > https://lists.sourceforge.net/lists/listinfo/matplotlib-users > |
From: Daniele N. <da...@gr...> - 2013-10-28 22:51:58
|
On 28/10/2013 23:30, Oliver wrote: > Hi Daniele, > > not sure, but it seems to work for me. Did you do a plt.draw() or > plt.show() to reflect the changes? Hello, it investigated this a bit further and the problem presents itself only when I use `mpl_toolkits.axisartist.Axes`. Here is a minimum example that demonstrates the problem: import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.axes_grid1 import host_subplot from mpl_toolkits.axisartist import Axes x = np.linspace(0, 2*np.pi) y = np.sin(x) f = plt.figure() BUG = True if BUG: ax1 = host_subplot(111, axes_class=Axes) else: ax1 = host_subplot(111, axes_class=Axes) ax1.plot(x, y) ax1.set_xlim(0, 2*np.pi) ax1.set_xticks(np.linspace(0, 2*np.pi, 5)) ax1.set_xticklabels(['%.2f' % x for x in np.linspace(0, 2*np.pi, 5)], fontsize=8) plt.draw() plt.show() Cheers, Daniele |
From: Daniele N. <da...@gr...> - 2013-10-28 23:37:42
|
On 29/10/2013 00:17, Sterling Smith wrote: > While your example tries to be self contained, which is great!, there is no difference between these two conditions... > >> if BUG: >> ax1 = host_subplot(111, axes_class=Axes) >> else: >> ax1 = host_subplot(111, axes_class=Axes) Ops, obvious mistake. It should read: BUG = True if BUG: ax1 = host_subplot(111 , axes_class=Axes) else: ax1 = host_subplot(111) Cheers, Daniele |
From: Ryan N. <rne...@gm...> - 2013-10-29 02:11:22
|
Daniele, I noticed the same problem with the Qt backend. However, I was looking at the documentation on the AxesGrid webpage here: http://matplotlib.org/mpl_toolkits/axes_grid/users/overview.html And I see the following warning: axes_grid and axisartist (but not axes_grid1) uses a custom Axes class (derived from the mpl’s original Axes class). As a side effect, some commands (mostly tick-related) do not work. Use axes_grid1 to avoid this, or see how things are different in axes_grid and axisartist (LINK needed) Unfortunately, no link. But perhaps there is a way to avoid using the Axes class from axisartist in your use case. For example, could you import the Axes class as follows: from matplotlib.axes import Axes That seems to work with the Qt and PDF backends on Windows 7 (Anaconda Python). Ryan On Mon, Oct 28, 2013 at 7:37 PM, Daniele Nicolodi <da...@gr...>wrote: > On 29/10/2013 00:17, Sterling Smith wrote: > > While your example tries to be self contained, which is great!, there is > no difference between these two conditions... > > > >> if BUG: > >> ax1 = host_subplot(111, axes_class=Axes) > >> else: > >> ax1 = host_subplot(111, axes_class=Axes) > > Ops, obvious mistake. It should read: > > BUG = True > if BUG: > ax1 = host_subplot(111 , axes_class=Axes) > else: > ax1 = host_subplot(111) > > > Cheers, > Daniele > > > > ------------------------------------------------------------------------------ > Android is increasing in popularity, but the open development platform that > developers love is also attractive to malware creators. Download this white > paper to learn more about secure code signing practices that can help keep > Android apps secure. > http://pubads.g.doubleclick.net/gampad/clk?id=65839951&iu=/4140/ostg.clktrk > _______________________________________________ > Matplotlib-users mailing list > Mat...@li... > https://lists.sourceforge.net/lists/listinfo/matplotlib-users > |
From: Daniele N. <da...@gr...> - 2013-10-29 09:54:09
|
On 29/10/2013 03:11, Ryan Nelson wrote: > Daniele, > > I noticed the same problem with the Qt backend. However, I was looking > at the documentation on the AxesGrid webpage here: > http://matplotlib.org/mpl_toolkits/axes_grid/users/overview.html > And I see the following warning: > > axes_grid and axisartist (but not axes_grid1) uses a custom Axes class > (derived from the mpl’s original Axes class). As a side effect, some > commands (mostly tick-related) do not work. Use axes_grid1 to avoid > this, or see how things are different in axes_grid and axisartist (LINK > needed) > > Unfortunately, no link. But perhaps there is a way to avoid using the > Axes class from axisartist in your use case. For example, could you > import the Axes class as follows: > > from matplotlib.axes import Axes > > That seems to work with the Qt and PDF backends on Windows 7 (Anaconda > Python). Hello Ryan, thanks for confirming the problem. I've also seen that note, but I thought "do not work" means that the methods raise an exception, not that they arbitrarily ignore arguments :( While the standard Axis class works for the cut-down example I posted, it does not for what I'm trying to achieve (having a second x axis below the main one). I came up with that solution following the matplotlib documentation: http://matplotlib.org/mpl_toolkits/axes_grid/users/overview.html#axisartist-with-parasiteaxes however I don't really understand why some of the contortions there are necessary (they are not explained in the documentation). Cheers, Daniele |
From: Ryan N. <rne...@gm...> - 2013-10-29 20:39:51
|
Daniele, I agree this is perhaps a little overly complicated. (However, once you figure it out, it does give you a ton of flexibility.) I played around with this a bit (thanks IPython!), and I may have figured out what you wanted to do. I rewrote the example you linked from the MPL website. I couldn't simplify it much, but it does change the size, location and labels of the floating y axis. ################# from mpl_toolkits.axes_grid1 import host_subplot import mpl_toolkits.axisartist as AA import matplotlib.pyplot as plt host = host_subplot(111, axes_class=AA.Axes) plt.subplots_adjust(right=0.75) par1 = host.twinx() par2 = host.twinx() offset = 60 new_fixed_axis = par2.get_grid_helper().new_fixed_axis par2.axis["right"] = new_fixed_axis(loc="right", axes=par2, offset=(offset, 0)) par2.axis["right"].toggle(all=True) p1, = host.plot([0, 1, 2], [0, 1, 2], label="Density") p2, = par1.plot([0, 1, 2], [0, 3, 2], label="Temperature") p3, = par2.plot([0, 1, 2], [50, 30, 15], label="Velocity") host.legend() host.set_xlabel("Distance") host.set_ylabel("Density") host.axis["left"].label.set_color(p1.get_color()) host.set_xlim(0, 2) host.set_ylim(0, 2) par1.set_ylabel("Temperature") par1.axis["right"].label.set_color(p2.get_color()) par1.set_ylim(0, 4) par2.set_ylabel("Velocity") par2.set_ylim(1, 65) par2.yaxis.set_ticks( (20.0, 40.0) ) par2.yaxis.set_ticklabels( ('A', 'B') ) par2.axis["right"].label.set_color(p3.get_color()) par2.axis["right"].label.set_fontsize(18) par2.axis["right"].major_ticklabels.set_fontsize(14) plt.show() ################## Hope that helps. Ryan On Tue, Oct 29, 2013 at 5:54 AM, Daniele Nicolodi <da...@gr...>wrote: > On 29/10/2013 03:11, Ryan Nelson wrote: > > Daniele, > > > > I noticed the same problem with the Qt backend. However, I was looking > > at the documentation on the AxesGrid webpage here: > > http://matplotlib.org/mpl_toolkits/axes_grid/users/overview.html > > And I see the following warning: > > > > axes_grid and axisartist (but not axes_grid1) uses a custom Axes class > > (derived from the mpl’s original Axes class). As a side effect, some > > commands (mostly tick-related) do not work. Use axes_grid1 to avoid > > this, or see how things are different in axes_grid and axisartist (LINK > > needed) > > > > Unfortunately, no link. But perhaps there is a way to avoid using the > > Axes class from axisartist in your use case. For example, could you > > import the Axes class as follows: > > > > from matplotlib.axes import Axes > > > > That seems to work with the Qt and PDF backends on Windows 7 (Anaconda > > Python). > > Hello Ryan, > > thanks for confirming the problem. I've also seen that note, but I > thought "do not work" means that the methods raise an exception, not > that they arbitrarily ignore arguments :( > > While the standard Axis class works for the cut-down example I posted, > it does not for what I'm trying to achieve (having a second x axis below > the main one). I came up with that solution following the matplotlib > documentation: > > > http://matplotlib.org/mpl_toolkits/axes_grid/users/overview.html#axisartist-with-parasiteaxes > > however I don't really understand why some of the contortions there are > necessary (they are not explained in the documentation). > > Cheers, > Daniele > > > > ------------------------------------------------------------------------------ > Android is increasing in popularity, but the open development platform that > developers love is also attractive to malware creators. Download this white > paper to learn more about secure code signing practices that can help keep > Android apps secure. > http://pubads.g.doubleclick.net/gampad/clk?id=65839951&iu=/4140/ostg.clktrk > _______________________________________________ > Matplotlib-users mailing list > Mat...@li... > https://lists.sourceforge.net/lists/listinfo/matplotlib-users > |
From: Daniele N. <da...@gr...> - 2013-10-30 11:16:46
|
On 29/10/2013 21:39, Ryan Nelson wrote: > Daniele, > > I agree this is perhaps a little overly complicated. (However, once you > figure it out, it does give you a ton of flexibility.) The main point is not that it is overly complicated, it is that is is severely under documented... > I played around > with this a bit (thanks IPython!), and I may have figured out what you > wanted to do. I rewrote the example you linked from the MPL website. I > couldn't simplify it much, but it does change the size, location and > labels of the floating y axis. Thanks! I didn't have the resources to investigate this further. > par2.axis["right"].major_ticklabels.set_fontsize(14) Well, this makes sense... Cheers, Daniele |