[Matplotlib-users] ImportError: No module named 'mpl_toolkits'
To matplotlib-users, When I do this on Linux: from mpl_toolkits.basemap import Basemap Then I get this error: ImportError: No module named 'mpl_toolkits' I also ran apt-get, but I still get the error: sudo apt-get install python-mpltoolkits.basemap What am I doing wrong? I also tried to get it to work on Mac with no luck. Thanks, Tommy -- ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] ValueError: The Cairo backend can not draw paths longer than 18980 points.
To matplotlib-users, When I do: cd basemap-1.0.7/examples python3 simpletest.py Then I get this error message: Traceback (most recent call last): File "/usr/local/lib/python3.4/dist-packages/matplotlib-1.3.1-py3.4-linux-i686.egg/matplotlib/backends/backend_gtk3cairo.py", line 32, in on_draw_event self._render_figure(w, h) File "/usr/local/lib/python3.4/dist-packages/matplotlib-1.3.1-py3.4-linux-i686.egg/matplotlib/backends/backend_gtk3cairo.py", line 21, in _render_figure self.figure.draw (self._renderer) File "/usr/local/lib/python3.4/dist-packages/matplotlib-1.3.1-py3.4-linux-i686.egg/matplotlib/artist.py", line 56, in draw_wrapper draw(artist, renderer, *args, **kwargs) File "/usr/local/lib/python3.4/dist-packages/matplotlib-1.3.1-py3.4-linux-i686.egg/matplotlib/figure.py", line 1035, in draw func(*args) File "/usr/local/lib/python3.4/dist-packages/matplotlib-1.3.1-py3.4-linux-i686.egg/matplotlib/artist.py", line 56, in draw_wrapper draw(artist, renderer, *args, **kwargs) File "/usr/local/lib/python3.4/dist-packages/matplotlib-1.3.1-py3.4-linux-i686.egg/matplotlib/axes.py", line 2088, in draw a.draw(renderer) File "/usr/local/lib/python3.4/dist-packages/matplotlib-1.3.1-py3.4-linux-i686.egg/matplotlib/artist.py", line 56, in draw_wrapper draw(artist, renderer, *args, **kwargs) File "/usr/local/lib/python3.4/dist-packages/matplotlib-1.3.1-py3.4-linux-i686.egg/matplotlib/collections.py", line 719, in draw return Collection.draw(self, renderer) File "/usr/local/lib/python3.4/dist-packages/matplotlib-1.3.1-py3.4-linux-i686.egg/matplotlib/artist.py", line 56, in draw_wrapper draw(artist, renderer, *args, **kwargs) File "/usr/local/lib/python3.4/dist-packages/matplotlib-1.3.1-py3.4-linux-i686.egg/matplotlib/collections.py", line 279, in draw self._offset_position) File "/usr/local/lib/python3.4/dist-packages/matplotlib-1.3.1-py3.4-linux-i686.egg/matplotlib/backend_bases.py", line 234, in draw_path_collection self.draw_path(gc0, path, transform, rgbFace) File "/usr/local/lib/python3.4/dist-packages/matplotlib-1.3.1-py3.4-linux-i686.egg/matplotlib/backends/backend_cairo.py", line 143, in draw_path raise ValueError("The Cairo backend can not draw paths longer than 18980 points.") ValueError: The Cairo backend can not draw paths longer than 18980 points. How can I get matplotlib basemap to work as expected? Thanks, Tommy -- ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] unable to run simpletest.py
To matplotlib-users, I ran the installation guide here on Mac OS: http://matplotlib.org/basemap/users/installing.html Except I did brew install geos and subsequently did: export DYLD_LIBRARY_PATH=/Users/tc9/homebrew/lib export GEOS_LIBRARY_PATH=/Users/tc9/homebrew/Cellar/geos/3.4.2 export GEOS_DIR=/Users/tc9/homebrew/Cellar/geos/3.4.2 And instead of python setup.py install I did: /usr/local/bin/python3 setup.py install --user I got this warning: /Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/distutils/dist.py:260: UserWarning: Unknown distribution option: 'namespace_packages' warnings.warn(msg) When I try to run simpletest.py in the folder examples with /usr/local/bin/python3 I get this error: Assertion failed: (0), function query, file AbstractSTRtree.cpp, line 285. Abort trap: 6 What am I doing wrong? Thanks, Tommy -- Comprehensive Server Monitoring with Site24x7. Monitor 10 servers for $9/Month. Get alerted through email, SMS, voice calls or mobile push notifications. Take corrective actions from your mobile device. http://p.sf.net/sfu/Zoho ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] python3 and basemap bluemarble()
To matplotlib-users, basemap bluemarble() requires PIL, which is not available for Python3. What is the usual workaround, when using Python and wanting to do bluemarble()? Thanks, Tommy -- Comprehensive Server Monitoring with Site24x7. Monitor 10 servers for $9/Month. Get alerted through email, SMS, voice calls or mobile push notifications. Take corrective actions from your mobile device. http://p.sf.net/sfu/Zoho ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] plot Africa only
Is it possible to tell matplotlib to only plot the African continent? http://tommycarstensen.com/python2_matplotlib_basemap_merc_bluemarble_hresolution.jpg I can do this in gnuplot, but I can't figure out how to do it with matplotlib/basemap. Thanks, Tommy -- Comprehensive Server Monitoring with Site24x7. Monitor 10 servers for $9/Month. Get alerted through email, SMS, voice calls or mobile push notifications. Take corrective actions from your mobile device. http://p.sf.net/sfu/Zoho ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] unable to run simpletest.py
Here is a more detailed crash report in addition to the one from the command line: Application Specific Information: Assertion failed: (0), function query, file AbstractSTRtree.cpp, line 285. Thread 0 Crashed:: Dispatch queue: com.apple.main-thread 0 libsystem_kernel.dylib 0x7fff93f2e866 __pthread_kill + 10 1 libsystem_pthread.dylib 0x7fff9a44035c pthread_kill + 92 2 libsystem_c.dylib 0x7fff935bfb1a abort + 125 3 libsystem_c.dylib 0x7fff935899bf __assert_rtn + 321 4 libgeos-3.4.2.dylib 0x000105df3e6b geos::index::strtree::AbstractSTRtree::query(void const*, geos::index::strtree::AbstractNode const*, std::__1::vector >*) + 363 5 libgeos-3.4.2.dylib 0x000105e09c4d geos::noding::MCIndexNoder::intersectChains() + 173 6 libgeos-3.4.2.dylib 0x000105e10514 geos::operation::buffer::BufferBuilder::computeNodedEdges(std::__1::vector >&, geos::geom::PrecisionModel const*) + 50 7 libgeos-3.4.2.dylib 0x000105e10028 geos::operation::buffer::BufferBuilder::buffer(geos::geom::Geometry const*, double) + 170 8 libgeos-3.4.2.dylib 0x000105e11e84 geos::operation::buffer::BufferOp::bufferOriginalPrecision() + 178 9 libgeos-3.4.2.dylib 0x000105e11d94 geos::operation::buffer::BufferOp::computeGeometry() + 14 10 libgeos-3.4.2.dylib 0x000105e11d35 geos::operation::buffer::BufferOp::bufferOp(geos::geom::Geometry const*, double, int, int) + 79 11 libgeos_c.1.dylib 0x000105ba8f9f GEOSBuffer_r + 42 12 _geoslib.so 0x0001056ee0ac __pyx_pw_8_geoslib_12BaseGeometry_11fix + 28 (_geoslib.c:1990) 13 org.python.python 0x0001000e5496 PyEval_EvalFrameEx + 31398 14 org.python.python 0x0001000e665d PyEval_EvalCodeEx + 2349 15 org.python.python 0x0001000e51f7 PyEval_EvalFrameEx + 30727 16 org.python.python 0x0001000e665d PyEval_EvalCodeEx + 2349 17 org.python.python 0x00010003f76a function_call + 186 18 org.python.python 0x0001da08 PyObject_Call + 104 19 org.python.python 0x00010002941c method_call + 140 20 org.python.python 0x0001da08 PyObject_Call + 104 21 org.python.python 0x000100078651 slot_tp_init + 81 22 org.python.python 0x0001000736c4 type_call + 212 23 org.python.python 0x0001da08 PyObject_Call + 104 24 org.python.python 0x0001000e1c3f PyEval_EvalFrameEx + 16975 25 org.python.python 0x0001000e665d PyEval_EvalCodeEx + 2349 26 org.python.python 0x0001000e671f PyEval_EvalCode + 63 27 org.python.python 0x000100110b2e PyRun_FileExFlags + 206 28 org.python.python 0x000100110edd PyRun_SimpleFileExFlags + 717 29 org.python.python 0x00010012856e Py_Main + 3262 30 org.python.python 0x00010e32 0x1 + 3634 31 org.python.python 0x00010c84 0x1 + 3204 On Fri, Oct 17, 2014 at 3:57 AM, Tommy Carstensen wrote: > To matplotlib-users, > > I ran the installation guide here on Mac OS: > http://matplotlib.org/basemap/users/installing.html > > Except I did brew install geos and subsequently did: > export DYLD_LIBRARY_PATH=/Users/tc9/homebrew/lib > export GEOS_LIBRARY_PATH=/Users/tc9/homebrew/Cellar/geos/3.4.2 > export GEOS_DIR=/Users/tc9/homebrew/Cellar/geos/3.4.2 > > And instead of python setup.py install I did: > /usr/local/bin/python3 setup.py install --user > > I got this warning: > /Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/distutils/dist.py:260: > UserWarning: Unknown distribution option: 'namespace_packages' > warnings.warn(msg) > > When I try to run simpletest.py in the folder examples with > /usr/local/bin/python3 I get this error: > Assertion failed: (0), function query, file AbstractSTRtree.cpp, line 285. > Abort trap: 6 > > What am I doing wrong? > > Thanks, > Tommy -- Comprehensive Server Monitoring with Site24x7. Monitor 10 servers for $9/Month. Get alerted through email, SMS, voice calls or mobile push notifications. Take corrective actions from your mobile device. http://p.sf.net/sfu/Zoho ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] adding legends
Does anyone know, how they were able to add the legend titles "damped" and "oscillatory" to this plot: http://matplotlib.org/examples/pylab_examples/legend_demo.html Can anyone point me to a good tutorial on matplotlib legends? This one is somewhat limited: http://matplotlib.org/users/legend_guide.html Thanks. -- Comprehensive Server Monitoring with Site24x7. Monitor 10 servers for $9/Month. Get alerted through email, SMS, voice calls or mobile push notifications. Take corrective actions from your mobile device. http://p.sf.net/sfu/Zoho ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] avoid duplicate legends
How does one avoid duplicate legends? www.tommycarstensen.com/python2_matplotlib_basemap_merc_bluemarble_hresolution.jpg Can I make the legend size smaller than the marker size? -- Comprehensive Server Monitoring with Site24x7. Monitor 10 servers for $9/Month. Get alerted through email, SMS, voice calls or mobile push notifications. Take corrective actions from your mobile device. http://p.sf.net/sfu/Zoho ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] avoid duplicate legends
I was able to solve my two problems by doing label="" and numpoints=1. Thank you very much for your help. I found my solution here: http://stackoverflow.com/questions/19385639/duplicate-items-in-legend-in-matplotlib There is also another cleaner solution here: http://stackoverflow.com/questions/13588920/stop-matplotlib-repeating-labels-in-legend import matplotlib matplotlib.use('Agg') from mpl_toolkits.basemap import Basemap import matplotlib.pyplot as plt map = Basemap() map.plot(label="") plt.legend(numpoints=1) On Mon, Oct 20, 2014 at 8:11 AM, Benjamin Root wrote: > Legends entries are blindly constructed. Each plotting call that has a > legend keyword argument will produce a legend entry if you are automatically > building the legend. You can pass a label value of "__nolabel__" to prevent > an entry if you know you are about to do something that would duplicate the > entries. Another approach is to manually collect unique artists and manually > build the legend (I think there is an example of that in the gallary). > > As for configuring the legend, there are a bunch of parameters that can be > set for sizing the font. I think the sizing of the marker is determined by > their size in the plot, though. > > Cheers! > Ben Root > > > On Mon, Oct 20, 2014 at 10:46 AM, Hearne, Mike wrote: >> >> For your first question: Use the legend "numpoints" keyword. I think >> if you set it to 1, it should solve that problem. >> >> For your second question, I'm not sure, but I'll bet if you poke >> around in the Legend object returned by the function, you'll find >> something. >> >> On Mon, Oct 20, 2014 at 8:04 AM, Tommy Carstensen >> wrote: >> > How does one avoid duplicate legends? >> > >> > www.tommycarstensen.com/python2_matplotlib_basemap_merc_bluemarble_hresolution.jpg >> > >> > Can I make the legend size smaller than the marker size? >> > >> > >> > -- >> > Comprehensive Server Monitoring with Site24x7. >> > Monitor 10 servers for $9/Month. >> > Get alerted through email, SMS, voice calls or mobile push >> > notifications. >> > Take corrective actions from your mobile device. >> > http://p.sf.net/sfu/Zoho >> > ___ >> > Matplotlib-users mailing list >> > Matplotlib-users@lists.sourceforge.net >> > https://lists.sourceforge.net/lists/listinfo/matplotlib-users >> >> >> -- >> Comprehensive Server Monitoring with Site24x7. >> Monitor 10 servers for $9/Month. >> Get alerted through email, SMS, voice calls or mobile push notifications. >> Take corrective actions from your mobile device. >> http://p.sf.net/sfu/Zoho >> ___ >> Matplotlib-users mailing list >> Matplotlib-users@lists.sourceforge.net >> https://lists.sourceforge.net/lists/listinfo/matplotlib-users > > -- ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] markers with same size in legend box
Is there a way to have all markers in the legend box have the same size? www.tommycarstensen.com/python3_matplotlib_basemap_merc_bluemarbleTrue_scaledTrue_1000GTrue_hresolution.jpg I came up with a solution by plotting a marker outside the latitude and longitude range, but that's not a very good solution. Thanks for your time. -- ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] plot Africa only
Does anyone know, whether a continent can be left out when plotting with matplotlib basemap? For example I wish to hide Europe (and Madagascar) on this plot: http://www.tommycarstensen.com/python3_matplotlib_basemap_merc_bluemarbleTrue_scaledTrue_1000GTrue_hresolution.jpg On Sat, Oct 18, 2014 at 7:57 AM, Tommy Carstensen wrote: > Is it possible to tell matplotlib to only plot the African continent? > http://tommycarstensen.com/python2_matplotlib_basemap_merc_bluemarble_hresolution.jpg > > I can do this in gnuplot, but I can't figure out how to do it with > matplotlib/basemap. > > Thanks, > Tommy -- ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] markers with same size in legend box
Thanks for feedback Thomas and Sterling. Here is the ugly solution I ended up with: # plot a marker with a blank label map.plot(x, y, 'o', markersize=markersize, markerfacecolor=color, label="") # specify a coordinate outside the map region (Africa) x,y = map(-60, -60) # use a fixed markersize for coordinates outside the map region and use a non-blank label map.plot(x, y, 'o', markersize=10, markerfacecolor=color, label=label) I should have used proxy artists as suggested by Sterling. Here is an example: http://matplotlib.org/users/legend_guide.html#proxy-legend-handles import matplotlib.patches as mpatches import matplotlib.pyplot as plt red_patch = mpatches.Patch(color='red', label='The red data') plt.legend(handles=[red_patch]) plt.show() On Fri, Oct 24, 2014 at 7:36 PM, Sterling Smith wrote: > Your solution is about as good as "proxy artists" in legends, which would be > the official method. (Google "proxy artist matplotlib".) > > It may be relevant that you can access the marker of the legend entries with > the _marker attribute of the handles. Search the mailing list archives for > this one. > > -Sterling > > On Oct 23, 2014, at 8:05PM, Tommy Carstensen wrote: > >> Is there a way to have all markers in the legend box have the same size? >> www.tommycarstensen.com/python3_matplotlib_basemap_merc_bluemarbleTrue_scaledTrue_1000GTrue_hresolution.jpg >> >> I came up with a solution by plotting a marker outside the latitude >> and longitude range, but that's not a very good solution. >> >> Thanks for your time. >> >> -- >> ___ >> Matplotlib-users mailing list >> Matplotlib-users@lists.sourceforge.net >> https://lists.sourceforge.net/lists/listinfo/matplotlib-users > -- ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] plot Africa only
Felipe, thanks for the links! I do realize it would be impossible to leave out non-African mainland when using bluemarble(). I could color Europe, Madagascar, Middle East white on a map with filled continents, but I would have to be accurate at the Israel/Egypt, Djibouti/Yemen and Spain/Morocco borders. Not the solution I was looking to implement. Using Cartopy and a shapefile of Africa seems to be a very good solution. I'll look into this. Thanks! On Fri, Oct 24, 2014 at 12:25 PM, Filipe Pires Alvarenga Fernandes wrote: > Hi Tommy, there is not easy way to do it with matplolib+basemap. Also, you > will find it extra hard because the image you are plotting (blue marble) is > raster that is cut in lon, lat bounding box. Therefore, unless you create a > mask around what to plot and what not to plot, it will show everything that > is inside that box. > > One alternative is cartopy. With cartopy you have easy access to Natural > Earth features. That way you can find the proper feature, that represents > just the African continent, and plot it: > > http://scitools.org.uk/cartopy/docs/latest/examples/hurricane_katrina.html > > https://ocefpaf.github.io/python4oceanographers/blog/2013/09/30/natural_earth/ > > Good luck! > > -Filipe > > On Fri, Oct 24, 2014 at 7:21 AM, Tommy Carstensen > wrote: >> >> Does anyone know, whether a continent can be left out when plotting >> with matplotlib basemap? For example I wish to hide Europe (and >> Madagascar) on this plot: >> >> http://www.tommycarstensen.com/python3_matplotlib_basemap_merc_bluemarbleTrue_scaledTrue_1000GTrue_hresolution.jpg > > > -- > > ___ > Matplotlib-users mailing list > Matplotlib-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/matplotlib-users > -- ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] two axes
In gnuplot it is quite easy to create two axes, but I can't figure out how to do it in matplotlib. I'm trying this: import matplotlib matplotlib.use('Agg') import matplotlib.pyplot as plt for key1 in keys1: ax1.plot(x, y, style, label=label, color=color, linewidth=3) ax1.set_xlabel(xlabel) ax1.set_ylabel(ylabel1) ax2.set_ylabel(ylabel2) plt.legend(loc='lower right', shadow=True) plt.suptitle(title, fontsize=14, fontweight='bold') axes = plt.gca() axes.set_ylim([0,1]) plt.grid(b=True, which='major', color='k', linestyle='--') plt.savefig('{}.png'.format(key1), dpi=600) plt.close() plt.clf() But I get this error: lib/python3.3/site-packages/matplotlib/axes.py:4749: UserWarning: No labeled objects found. Use label='...' kwarg on individual plots. warnings.warn("No labeled objects found. " What am I doing wrong? Thanks. -- Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server from Actuate! Instantly Supercharge Your Business Reports and Dashboards with Interactivity, Sharing, Native Excel Exports, App Integration & more Get technology previously reserved for billion-dollar corporations, FREE http://pubads.g.doubleclick.net/gampad/clk?id=157005751&iu=/4140/ostg.clktrk ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] horizontal alignment of a secondary y-axis
How can I set the horizontal alignment of a secondary y-axis to 'right'? Currently the numbers are glued to the axis. I want the axis values to be right aligned integers. Thanks. -- Dive into the World of Parallel Programming. The Go Parallel Website, sponsored by Intel and developed in partnership with Slashdot Media, is your hub for all things parallel software development, from weekly thought leadership blogs to news, videos, case studies, tutorials and more. Take a look and join the conversation now. http://goparallel.sourceforge.net/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] MultipleLocator and MaxNLocator
Is it possible to combine MultipleLocator and MaxNLocator? One seems to erase the effect of the other. -- Dive into the World of Parallel Programming. The Go Parallel Website, sponsored by Intel and developed in partnership with Slashdot Media, is your hub for all things parallel software development, from weekly thought leadership blogs to news, videos, case studies, tutorials and more. Take a look and join the conversation now. http://goparallel.sourceforge.net/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] horizontal alignment of a secondary y-axis
Hi Ryan, Thanks for your answer. Sorry for not replying sooner. I fell asleep shortly after sending my question. What is "the OO way"? Your 1st solution gives: AttributeError: 'module' object has no attribute 'ticks' I modified your 2nd solution to accommodate my wishes and needs: import matplotlib.pyplot as plt fig = plt.figure() ax1 = fig.add_subplot(111) ax2 = ax1.twinx() for label in ax2.yaxis.get_ticklabels(): label.set_horizontalalignment('right') ax2.tick_params(pad=20) ax1.plot(list(range(11))) ax1.set_xlim(0,10) ax2.set_ylim(0,10) plt.show() It seems like an awful hack with that for loop, but it works. I'm not sure, why the secondary right hand side axis don't have right aligned labels by default. That would make a lot of sense. It would be great, if I could set the horizontal alignment without having to use a for loop. It's just plain ugly. In gnuplot it's as simple as this: set ytics right Thanks for your help and providing me with a solution. Tommy On Sat, Feb 14, 2015 at 1:31 AM, Ryan Nelson wrote: > Tommy, > > You are probably looking for pyplot.xticks. For example, you might want > something along these lines: > > import matplotlib.pyplot as plt > plt.plot([1,3,2]) > # We'll do this to get the autogenerated positions > ticks, labels = plt.xticks() > plt.ticks(ticks, horizontalalignment='left') > plt.show() > > Or if your using the OO way: > > import matplotlib.pyplot as plt > fig = plt.figure() > ax = fig.add_subplot(111) > ax.plot([1,3,2]) > labels = ax.get_xticklabels() > [l.set_horizontalalignment('left') for l in labels] > plt.show() > > I think that's the best way. Hope it helps. > > Ryan > > > > On Fri, Feb 13, 2015 at 7:29 PM, Tommy Carstensen > wrote: >> >> How can I set the horizontal alignment of a secondary y-axis to >> 'right'? Currently the numbers are glued to the axis. I want the axis >> values to be right aligned integers. Thanks. >> >> >> -- >> Dive into the World of Parallel Programming. The Go Parallel Website, >> sponsored by Intel and developed in partnership with Slashdot Media, is >> your >> hub for all things parallel software development, from weekly thought >> leadership blogs to news, videos, case studies, tutorials and more. Take a >> look and join the conversation now. http://goparallel.sourceforge.net/ >> ___ >> Matplotlib-users mailing list >> Matplotlib-users@lists.sourceforge.net >> https://lists.sourceforge.net/lists/listinfo/matplotlib-users > > -- Dive into the World of Parallel Programming. The Go Parallel Website, sponsored by Intel and developed in partnership with Slashdot Media, is your hub for all things parallel software development, from weekly thought leadership blogs to news, videos, case studies, tutorials and more. Take a look and join the conversation now. http://goparallel.sourceforge.net/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] MultipleLocator and MaxNLocator
Thanks for you answer Eric. I had to get some sleep before trying out things. I currently have the code below, but it does not remove the zero value tick. It removes the tick at 5 and 10 however. import matplotlib.pyplot as plt from matplotlib.ticker import MultipleLocator fig = plt.figure() ax1 = fig.add_subplot(111) ax1.xaxis.set_major_locator(MultipleLocator(5)) xticks = ax1.xaxis.get_major_ticks() #xticks[0].label1.set_visible(False) #xticks[-1].label1.set_visible(False) ax1.set_xticks(ax1.get_xticks()[1:-1]) ax1.plot(list(range(11))) plt.show() On Sat, Feb 14, 2015 at 2:01 AM, Eric Firing wrote: > On 2015/02/13 3:29 PM, Tommy Carstensen wrote: >> Is it possible to combine MultipleLocator and MaxNLocator? One seems >> to erase the effect of the other. > > They are for different situations. MultipleLocator is for when you know > what you want your tick interval to be; MaxNLocator is for when you > don't know that, but you do know roughly how many ticks you want, and > what sort of numerical intervals are acceptable. > > Eric > > > -- > Dive into the World of Parallel Programming. The Go Parallel Website, > sponsored by Intel and developed in partnership with Slashdot Media, is your > hub for all things parallel software development, from weekly thought > leadership blogs to news, videos, case studies, tutorials and more. Take a > look and join the conversation now. http://goparallel.sourceforge.net/ > ___ > Matplotlib-users mailing list > Matplotlib-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/matplotlib-users -- Dive into the World of Parallel Programming. The Go Parallel Website, sponsored by Intel and developed in partnership with Slashdot Media, is your hub for all things parallel software development, from weekly thought leadership blogs to news, videos, case studies, tutorials and more. Take a look and join the conversation now. http://goparallel.sourceforge.net/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] horizontal alignment of a secondary y-axis
Whoa, thanks for a great answer Ryan. I can see, why the level of control MPL gives you is a great sales pitch. It's one of the reasons, why I switched from gnuplot after using it for many years and making many cool plots. The MPL learning curve has just been a bit steep, when you are used to plot whatever you want. On Sat, Feb 14, 2015 at 5:06 PM, Ryan Nelson wrote: > Tommy, > > I'll try to answer your points in order: > > 1) Oops. That should have been "xticks". > import matplotlib.pyplot as plt > plt.plot([1,3,2]) > ticks, labels = plt.xticks() > plt.xticks(ticks, horizontalalignment='left') > plt.show() > > > 2) Sorry for the ambiguity. "OO" is short for object-oriented. There are two > different approaches that people tend to use to make plots (although they > can be mixed): 1) the "pyplot" way, which uses the pyplot wrapper functions > and 2) the object-oriented way, which modifies the objects directly. This is > what you did in your example where you snag the axes objects and operate on > them directly. The "OO" way is ultimately more powerful, because the pyplot > wrapper functions override some of your control. For example, because you > want twin axes, you might not be able to use the pyplot.xticks function > (Others, correct me if I'm wrong.), and you lose some fine control. See next > example. > > 3) I know it *seems* like the for loop is an "ugly hack". However, you have > to realize that this ultimately gives you a TON of control. Let's say, for > example, that you wanted only one of the labels to be large and red to > highlight a certain value. Using a modified version of your example, we get > this: > __ > import matplotlib.pyplot as plt > fig = plt.figure() > ax1 = fig.add_subplot(111) > ax2 = ax1.twinx() > labels = ax2.yaxis.get_ticklabels() > [l.set_horizontalalignment('right') for l in labels] > labels[2].set_color('red') > labels[2].set_fontsize(20) > ax2.tick_params(pad=20) > ax1.plot(list(range(11))) > ax1.set_xlim(0,10) > ax2.set_ylim(0,10) > plt.show() > > I personally think that this level of control is very, very cool and one of > the big selling points for MPL in general. > > Okay. If you want to set the alignment all the time, there might be a way to > control this with matplotlibrc or style sheets: > http://matplotlib.org/users/customizing.html > http://matplotlib.org/users/style_sheets.html > However, I'm not the biggest fan of changing matplotlibrc. Mostly because if > others try to reproduce your plots, they also need your rc file as well. I > haven't used style sheets yet, but that might be a fix to this issue (for me > at least). > > Hope that helps. > > Ryan > > On Sat, Feb 14, 2015 at 10:30 AM, Tommy Carstensen > wrote: >> >> Hi Ryan, >> >> Thanks for your answer. Sorry for not replying sooner. I fell asleep >> shortly after sending my question. >> >> What is "the OO way"? >> >> Your 1st solution gives: >> AttributeError: 'module' object has no attribute 'ticks' >> >> I modified your 2nd solution to accommodate my wishes and needs: >> import matplotlib.pyplot as plt >> fig = plt.figure() >> ax1 = fig.add_subplot(111) >> ax2 = ax1.twinx() >> for label in ax2.yaxis.get_ticklabels(): >> label.set_horizontalalignment('right') >> ax2.tick_params(pad=20) >> ax1.plot(list(range(11))) >> ax1.set_xlim(0,10) >> ax2.set_ylim(0,10) >> plt.show() >> >> It seems like an awful hack with that for loop, but it works. I'm not >> sure, why the secondary right hand side axis don't have right aligned >> labels by default. That would make a lot of sense. It would be great, >> if I could set the horizontal alignment without having to use a for >> loop. It's just plain ugly. In gnuplot it's as simple as this: >> set ytics right >> >> Thanks for your help and providing me with a solution. >> >> Tommy >> >> On Sat, Feb 14, 2015 at 1:31 AM, Ryan Nelson >> wrote: >> > Tommy, >> > >> > You are probably looking for pyplot.xticks. For example, you might want >> > something along these lines: >> > >> > import matplotlib.pyplot as plt >> > plt.plot([1,3,2]) >> > # We'll do this to get the autogenerated positions >> > ticks, labels = plt.xticks() >> > plt.ticks(ticks, horizontalalignment='left') >> > plt.show() >> > >> > Or if your using the OO way: >> > >> >
Re: [Matplotlib-users] MultipleLocator and MaxNLocator
Thanks again Ryan. That's exactly what I want to achieve; i.e. remove the tick at 0 and only keep 5 and 10. Your solution works, but it's a bit of hack to use magic constants. I could however get those values from the xlim. Eric, I would describe the desired tick placement algorithm as removing the first tick on the axis. It can be achieved like this: ax1.xaxis.set_major_locator(MaxNLocator(prune='lower')) But that then overrides this: ax1.xaxis.set_major_locator(MultipleLocator(5)) On Sat, Feb 14, 2015 at 5:27 PM, Ryan Nelson wrote: > Tommy, (Sorry for the doubleup. I just realized I forgot to hit reply-all.) > > Do you want to remove the tick at 0 and only have 5,10, etc.? Could you just > do something like this instead: > > import matplotlib.pyplot as plt > from matplotlib.ticker import MultipleLocator > fig = plt.figure() > ax1 = fig.add_subplot(111) > ax1.set_xticks(range(5,11,5)) > ax1.plot(range(11)) > plt.show() > > Ryan > > > On Sat, Feb 14, 2015 at 10:47 AM, Tommy Carstensen > wrote: >> >> Thanks for you answer Eric. I had to get some sleep before trying out >> things. I currently have the code below, but it does not remove the >> zero value tick. It removes the tick at 5 and 10 however. >> >> import matplotlib.pyplot as plt >> from matplotlib.ticker import MultipleLocator >> fig = plt.figure() >> ax1 = fig.add_subplot(111) >> ax1.xaxis.set_major_locator(MultipleLocator(5)) >> xticks = ax1.xaxis.get_major_ticks() >> #xticks[0].label1.set_visible(False) >> #xticks[-1].label1.set_visible(False) >> ax1.set_xticks(ax1.get_xticks()[1:-1]) >> ax1.plot(list(range(11))) >> plt.show() >> >> On Sat, Feb 14, 2015 at 2:01 AM, Eric Firing wrote: >> > On 2015/02/13 3:29 PM, Tommy Carstensen wrote: >> >> Is it possible to combine MultipleLocator and MaxNLocator? One seems >> >> to erase the effect of the other. >> > >> > They are for different situations. MultipleLocator is for when you know >> > what you want your tick interval to be; MaxNLocator is for when you >> > don't know that, but you do know roughly how many ticks you want, and >> > what sort of numerical intervals are acceptable. >> > >> > Eric >> > >> > >> > >> > -- >> > Dive into the World of Parallel Programming. The Go Parallel Website, >> > sponsored by Intel and developed in partnership with Slashdot Media, is >> > your >> > hub for all things parallel software development, from weekly thought >> > leadership blogs to news, videos, case studies, tutorials and more. Take >> > a >> > look and join the conversation now. http://goparallel.sourceforge.net/ >> > ___ >> > Matplotlib-users mailing list >> > Matplotlib-users@lists.sourceforge.net >> > https://lists.sourceforge.net/lists/listinfo/matplotlib-users >> >> >> -- >> Dive into the World of Parallel Programming. The Go Parallel Website, >> sponsored by Intel and developed in partnership with Slashdot Media, is >> your >> hub for all things parallel software development, from weekly thought >> leadership blogs to news, videos, case studies, tutorials and more. Take a >> look and join the conversation now. http://goparallel.sourceforge.net/ >> ___ >> Matplotlib-users mailing list >> Matplotlib-users@lists.sourceforge.net >> https://lists.sourceforge.net/lists/listinfo/matplotlib-users > > -- Dive into the World of Parallel Programming. The Go Parallel Website, sponsored by Intel and developed in partnership with Slashdot Media, is your hub for all things parallel software development, from weekly thought leadership blogs to news, videos, case studies, tutorials and more. Take a look and join the conversation now. http://goparallel.sourceforge.net/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] MultipleLocator and MaxNLocator
Erik, that doesn't seem to work either. I tried this: import matplotlib.pyplot as plt from matplotlib.ticker import MultipleLocator class TrimmedMultipleLocator(MultipleLocator): def tick_values(self, vmin, vmax): return MultipleLocator.tick_values(self, vmin, vmax)[2:] fig = plt.figure() ax1 = fig.add_subplot(111) ax1.xaxis.set_major_locator(TrimmedMultipleLocator(5)) #xticks[0].label1.set_visible(False) #xticks[-1].label1.set_visible(False) #ax1.set_xticks(ax1.xaxis.get_major_ticks()[1:-1]) ax1.plot(list(range(21))) plt.show() Here is an example of the use of prune='lower', but it does not allow one to set the tick step size: http://stackoverflow.com/questions/9422587/overlapping-y-axis-tick-label-and-x-axis-tick-label-in-matplotlib I think my best bet is to just set those ticks manually. On Sat, Feb 14, 2015 at 6:19 PM, Eric Firing wrote: > On 2015/02/14 7:33 AM, Tommy Carstensen wrote: >> Thanks again Ryan. That's exactly what I want to achieve; i.e. remove >> the tick at 0 and only keep 5 and 10. Your solution works, but it's a >> bit of hack to use magic constants. I could however get those values >> from the xlim. >> >> Eric, I would describe the desired tick placement algorithm as >> removing the first tick on the axis. It can be achieved like this: >> ax1.xaxis.set_major_locator(MaxNLocator(prune='lower')) > > Aha! The problem is that the MaxNLocator is the only one with the prune > kwarg. It could be added to the MultipleLocator. For now, though, you > can make your own specialized Locator, hardwired to omit the first tick, > like this: > > from matplotlib.ticker import MultipleLocator > > class TrimmedMultipleLocator(MultipleLocator): > def tick_values(self, vmin, vmax): > return MultipleLocator.tick_values(self, vmin, vmax)[1:] > > then just use > > ax1.xaxis.set_major_locator(TrimmedMultipleLocator(5)) > > I haven't tested it--but give it a try. What it is doing is making a > subclass of MultipleLocator, and altering only the one little bit of its > behavior that you want to modify. Everything else is automatically > inherited from the base class, MultipleLocator. > > Eric > > >> >> But that then overrides this: >> ax1.xaxis.set_major_locator(MultipleLocator(5)) >> >> On Sat, Feb 14, 2015 at 5:27 PM, Ryan Nelson wrote: >>> Tommy, (Sorry for the doubleup. I just realized I forgot to hit reply-all.) >>> >>> Do you want to remove the tick at 0 and only have 5,10, etc.? Could you just >>> do something like this instead: >>> >>> import matplotlib.pyplot as plt >>> from matplotlib.ticker import MultipleLocator >>> fig = plt.figure() >>> ax1 = fig.add_subplot(111) >>> ax1.set_xticks(range(5,11,5)) >>> ax1.plot(range(11)) >>> plt.show() >>> >>> Ryan >>> >>> >>> On Sat, Feb 14, 2015 at 10:47 AM, Tommy Carstensen >>> wrote: >>>> >>>> Thanks for you answer Eric. I had to get some sleep before trying out >>>> things. I currently have the code below, but it does not remove the >>>> zero value tick. It removes the tick at 5 and 10 however. >>>> >>>> import matplotlib.pyplot as plt >>>> from matplotlib.ticker import MultipleLocator >>>> fig = plt.figure() >>>> ax1 = fig.add_subplot(111) >>>> ax1.xaxis.set_major_locator(MultipleLocator(5)) >>>> xticks = ax1.xaxis.get_major_ticks() >>>> #xticks[0].label1.set_visible(False) >>>> #xticks[-1].label1.set_visible(False) >>>> ax1.set_xticks(ax1.get_xticks()[1:-1]) >>>> ax1.plot(list(range(11))) >>>> plt.show() >>>> >>>> On Sat, Feb 14, 2015 at 2:01 AM, Eric Firing wrote: >>>>> On 2015/02/13 3:29 PM, Tommy Carstensen wrote: >>>>>> Is it possible to combine MultipleLocator and MaxNLocator? One seems >>>>>> to erase the effect of the other. >>>>> >>>>> They are for different situations. MultipleLocator is for when you know >>>>> what you want your tick interval to be; MaxNLocator is for when you >>>>> don't know that, but you do know roughly how many ticks you want, and >>>>> what sort of numerical intervals are acceptable. >>>>> >>>>> Eric >>>>> >>>>> >>>>> >>>>> -- >>>>> Dive into the World of Parallel Programming. The Go Parallel Website, >>>&
Re: [Matplotlib-users] MultipleLocator and MaxNLocator
Eric, it works if I do: return MultipleLocator.tick_values(self, vmin, vmax)[2:] But not if I do as first suggested by you: return MultipleLocator.tick_values(self, vmin, vmax)[1:] I don't understand this behaviour. It should be [1:]. I'll just set the ticks manually. Seems to be the easiest thing. It would be awesome, if MPL had the same behaviour as gnuplot, which allows me to simply do: set xtics , On Sat, Feb 14, 2015 at 7:09 PM, Eric Firing wrote: > On 2015/02/14 8:45 AM, Tommy Carstensen wrote: >> >> Erik, that doesn't seem to work either. I tried this: >> >> import matplotlib.pyplot as plt >> from matplotlib.ticker import MultipleLocator >> class TrimmedMultipleLocator(MultipleLocator): >> def tick_values(self, vmin, vmax): >> return MultipleLocator.tick_values(self, vmin, vmax)[2:] >> fig = plt.figure() >> ax1 = fig.add_subplot(111) >> ax1.xaxis.set_major_locator(TrimmedMultipleLocator(5)) >> #xticks[0].label1.set_visible(False) >> #xticks[-1].label1.set_visible(False) >> #ax1.set_xticks(ax1.xaxis.get_major_ticks()[1:-1]) >> ax1.plot(list(range(21))) >> plt.show() > > > Are you sure? I tried it, and it works for me. See attached script and > output. > > Eric > -- Dive into the World of Parallel Programming. The Go Parallel Website, sponsored by Intel and developed in partnership with Slashdot Media, is your hub for all things parallel software development, from weekly thought leadership blogs to news, videos, case studies, tutorials and more. Take a look and join the conversation now. http://goparallel.sourceforge.net/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] MultipleLocator and MaxNLocator
Ryan, my use case is indeed that I want to avoid overlapping ticks and I want to avoid them by not displaying them. Here is a guy with the same problem: http://stackoverflow.com/questions/9422587/overlapping-y-axis-tick-label-and-x-axis-tick-label-in-matplotlib Here is the problem at the top left of my plot: www.tommycarstensen.com/matplotlib.png I'll just set the ticks manually. Sadly seems like the easiest thing to do. On Sat, Feb 14, 2015 at 7:01 PM, Ryan Nelson wrote: > Tommy, > > I'm sorry. I forgot to hit send all *again*. Below is my original message, > but the function I wrote is updated because it wasn't exactly correct > > Ah. I was working on something to help out, so I'm just seeing Eric's very > elegant solution, which I have yet to try. However, I feel like you might > run into some problems if you always drop the first tick. For example, try > this plot: > __ > import matplotlib.pyplot as plt > from matplotlib.ticker import MultipleLocator > import numpy as np > xs = np.linspace(2,12,1000) > ys = np.sin(xs) > n = 5 > fig = plt.figure() > ax1 = fig.add_subplot(111) > ax1.plot(xs, ys) > ax1.xaxis.set_major_locator(MultipleLocator(5)) > plt.show() > _ > In this case, dropping the first tick will result in only one tick on the > screen. > > What is your use-case? Are you annoyed that the axis labels are overlapping > at the far left? If that's the case, here's a little function (trimticks) > that I whipped up that might help. It drops the far left or far right label > if it is exactly at the edge of the axes. Should work for y axes as well. > _ > def trimticks(ax, n=5): > xmin, xmax = ax.get_xlim() > if xmin%n == 0: > xmin = xmin+n > else: > xmin = xmin + n - xmin%n > > if not xmax%n == 0: > xmax = xmax + n - xmax%n > > ticks = np.arange(xmin, xmax, n) > ax.set_xticks(ticks) > > import matplotlib.pyplot as plt > from matplotlib.ticker import MultipleLocator > import numpy as np > xs = np.linspace(0,20,1) > ys = np.sin(xs) > fig = plt.figure() > ax1 = fig.add_subplot(111) > ax1.plot(xs, ys) > trimticks(ax1) > plt.show() > > ___ > > > On Sat, Feb 14, 2015 at 1:45 PM, Tommy Carstensen > wrote: >> >> Erik, that doesn't seem to work either. I tried this: >> >> import matplotlib.pyplot as plt >> from matplotlib.ticker import MultipleLocator >> class TrimmedMultipleLocator(MultipleLocator): >> def tick_values(self, vmin, vmax): >> return MultipleLocator.tick_values(self, vmin, vmax)[2:] >> fig = plt.figure() >> ax1 = fig.add_subplot(111) >> ax1.xaxis.set_major_locator(TrimmedMultipleLocator(5)) >> #xticks[0].label1.set_visible(False) >> #xticks[-1].label1.set_visible(False) >> #ax1.set_xticks(ax1.xaxis.get_major_ticks()[1:-1]) >> ax1.plot(list(range(21))) >> plt.show() >> >> Here is an example of the use of prune='lower', but it does not allow >> one to set the tick step size: >> >> http://stackoverflow.com/questions/9422587/overlapping-y-axis-tick-label-and-x-axis-tick-label-in-matplotlib >> >> I think my best bet is to just set those ticks manually. >> >> On Sat, Feb 14, 2015 at 6:19 PM, Eric Firing wrote: >> > On 2015/02/14 7:33 AM, Tommy Carstensen wrote: >> >> Thanks again Ryan. That's exactly what I want to achieve; i.e. remove >> >> the tick at 0 and only keep 5 and 10. Your solution works, but it's a >> >> bit of hack to use magic constants. I could however get those values >> >> from the xlim. >> >> >> >> Eric, I would describe the desired tick placement algorithm as >> >> removing the first tick on the axis. It can be achieved like this: >> >> ax1.xaxis.set_major_locator(MaxNLocator(prune='lower')) >> > >> > Aha! The problem is that the MaxNLocator is the only one with the prune >> > kwarg. It could be added to the MultipleLocator. For now, though, you >> > can make your own specialized Locator, hardwired to omit the first tick, >> > like this: >> > >> > from matplotlib.ticker import MultipleLocator >> > >> > class TrimmedMultipleLocator(MultipleLocator): >> > def tick_values(self, vmin, vmax): >> > return MultipleLocator.tick_values(self, vmin, vmax)[1:] >> > >> > then just use >> > >> > ax1.xaxis.set_major_locator(TrimmedMultipleLocator(5)) >> > >> > I haven't tested it--but give i
Re: [Matplotlib-users] MultipleLocator and MaxNLocator
Thanks Eric. I decided to get peace of mind and just set the tick labels manually. I can't afford to spend several hours on all of my plots. I appreciate your help a lot. On Sat, Feb 14, 2015 at 7:37 PM, Eric Firing wrote: > On 2015/02/14 9:15 AM, Tommy Carstensen wrote: >> >> Eric, it works if I do: >> return MultipleLocator.tick_values(self, vmin, vmax)[2:] >> >> But not if I do as first suggested by you: >> return MultipleLocator.tick_values(self, vmin, vmax)[1:] >> > > Are you using my test script but getting a different result? If not, what > is the difference in your test script? > >> I don't understand this behaviour. It should be [1:]. I'll just set >> the ticks manually. Seems to be the easiest thing. It would be >> awesome, if MPL had the same behaviour as gnuplot, which allows me to >> simply do: >> set xtics , > > > def xtics(ax, start, incr): > stop = ax.dataLim.x1 + 0.01 * incr > ax.xaxis.set_ticks(np.arange(start, stop, incr)) > > > Now invoke that function *after* all your plot calls, so that the dataLim > bounding box includes all the data in your plot. > > Eric -- Dive into the World of Parallel Programming. The Go Parallel Website, sponsored by Intel and developed in partnership with Slashdot Media, is your hub for all things parallel software development, from weekly thought leadership blogs to news, videos, case studies, tutorials and more. Take a look and join the conversation now. http://goparallel.sourceforge.net/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] MultipleLocator and MaxNLocator
Ryan, I stopped using gnuplot, because it requires the data to be formatted in very specific ways :) I remember having functions just to format the input data correctly for heat plots and the wrapper scripts I wrote were quite convoluted. Matplotlib has its advantages for sure. Otherwise I would not have switched. I'm just frustrated with being back at the start line. Thanks for your help and bearing with my impatience. On Sat, Feb 14, 2015 at 7:42 PM, Ryan Nelson wrote: > Yep. I see your problem. My function and Eric's object should help here. > > A sore-spot with many folks coming over to Matplotlib from "X" is the fact > that MPL does not calculate the size of text until the plot is generated. > That means it doesn't always get text positioning, etc. exactly correct. > That takes a little getting used to, and for me, it is minor. > > Admit it, Gnuplot as it's quirks as well :) I always hated that it wouldn't > cut off some markers at the edge of the screen. For example, with Gnuplot > 4.6rev5 the following > plot x with points ps 7 > Leads to a bunch of markers running over the axes limits. (Maybe there is a > way to fix this now. Many years ago that was not the case.) > > Ryan > > On Sat, Feb 14, 2015 at 2:18 PM, Tommy Carstensen > wrote: >> >> Ryan, my use case is indeed that I want to avoid overlapping ticks and >> I want to avoid them by not displaying them. Here is a guy with the >> same problem: >> >> http://stackoverflow.com/questions/9422587/overlapping-y-axis-tick-label-and-x-axis-tick-label-in-matplotlib >> >> Here is the problem at the top left of my plot: >> www.tommycarstensen.com/matplotlib.png >> >> I'll just set the ticks manually. Sadly seems like the easiest thing to >> do. >> >> On Sat, Feb 14, 2015 at 7:01 PM, Ryan Nelson >> wrote: >> > Tommy, >> > >> > I'm sorry. I forgot to hit send all *again*. Below is my original >> > message, >> > but the function I wrote is updated because it wasn't exactly >> > correct >> > >> > Ah. I was working on something to help out, so I'm just seeing Eric's >> > very >> > elegant solution, which I have yet to try. However, I feel like you >> > might >> > run into some problems if you always drop the first tick. For example, >> > try >> > this plot: >> > __ >> > import matplotlib.pyplot as plt >> > from matplotlib.ticker import MultipleLocator >> > import numpy as np >> > xs = np.linspace(2,12,1000) >> > ys = np.sin(xs) >> > n = 5 >> > fig = plt.figure() >> > ax1 = fig.add_subplot(111) >> > ax1.plot(xs, ys) >> > ax1.xaxis.set_major_locator(MultipleLocator(5)) >> > plt.show() >> > _ >> > In this case, dropping the first tick will result in only one tick on >> > the >> > screen. >> > >> > What is your use-case? Are you annoyed that the axis labels are >> > overlapping >> > at the far left? If that's the case, here's a little function >> > (trimticks) >> > that I whipped up that might help. It drops the far left or far right >> > label >> > if it is exactly at the edge of the axes. Should work for y axes as >> > well. >> > _ >> > def trimticks(ax, n=5): >> > xmin, xmax = ax.get_xlim() >> > if xmin%n == 0: >> > xmin = xmin+n >> > else: >> > xmin = xmin + n - xmin%n >> > >> > if not xmax%n == 0: >> > xmax = xmax + n - xmax%n >> > >> > ticks = np.arange(xmin, xmax, n) >> > ax.set_xticks(ticks) >> > >> > import matplotlib.pyplot as plt >> > from matplotlib.ticker import MultipleLocator >> > import numpy as np >> > xs = np.linspace(0,20,1) >> > ys = np.sin(xs) >> > fig = plt.figure() >> > ax1 = fig.add_subplot(111) >> > ax1.plot(xs, ys) >> > trimticks(ax1) >> > plt.show() >> > >> > ___ >> > >> > >> > On Sat, Feb 14, 2015 at 1:45 PM, Tommy Carstensen >> > wrote: >> >> >> >> Erik, that doesn't seem to work either. I tried this: >> >> >> >> import matplotlib.pyplot as plt >> >> from matplotlib.ticker import MultipleLocator >> >> class TrimmedMultipleLocator(MultipleLocator): >> >> def tick_values(self, vmin, vmax): >> >>
Re: [Matplotlib-users] horizontal alignment of a secondary y-axis
Ryan, do you know, if there is any way I can make the padding dependent on the tick label sizes? for label in ax2.yaxis.get_ticklabels(): label.set_horizontalalignment('right') ax2.tick_params(pad=20) When the numbers are large, then they are glued to the secondary y-axis. When they are small, then they are hovering far away from it. On Sat, Feb 14, 2015 at 7:20 PM, Ryan Nelson wrote: > You're welcome, Tommy. I used gnuplot many years ago, but I've been much > happier now that I know MPL. > > A gnuplot->MPL Rosetta Stone might be a useful blog post for someone. I > haven't used gnuplot in so long that I don't think I could do this myself. > > R > > On Sat, Feb 14, 2015 at 12:28 PM, Tommy Carstensen > wrote: >> >> Whoa, thanks for a great answer Ryan. I can see, why the level of >> control MPL gives you is a great sales pitch. It's one of the reasons, >> why I switched from gnuplot after using it for many years and making >> many cool plots. The MPL learning curve has just been a bit steep, >> when you are used to plot whatever you want. >> >> On Sat, Feb 14, 2015 at 5:06 PM, Ryan Nelson >> wrote: >> > Tommy, >> > >> > I'll try to answer your points in order: >> > >> > 1) Oops. That should have been "xticks". >> > import matplotlib.pyplot as plt >> > plt.plot([1,3,2]) >> > ticks, labels = plt.xticks() >> > plt.xticks(ticks, horizontalalignment='left') >> > plt.show() >> > >> > >> > 2) Sorry for the ambiguity. "OO" is short for object-oriented. There are >> > two >> > different approaches that people tend to use to make plots (although >> > they >> > can be mixed): 1) the "pyplot" way, which uses the pyplot wrapper >> > functions >> > and 2) the object-oriented way, which modifies the objects directly. >> > This is >> > what you did in your example where you snag the axes objects and operate >> > on >> > them directly. The "OO" way is ultimately more powerful, because the >> > pyplot >> > wrapper functions override some of your control. For example, because >> > you >> > want twin axes, you might not be able to use the pyplot.xticks function >> > (Others, correct me if I'm wrong.), and you lose some fine control. See >> > next >> > example. >> > >> > 3) I know it *seems* like the for loop is an "ugly hack". However, you >> > have >> > to realize that this ultimately gives you a TON of control. Let's say, >> > for >> > example, that you wanted only one of the labels to be large and red to >> > highlight a certain value. Using a modified version of your example, we >> > get >> > this: >> > __ >> > import matplotlib.pyplot as plt >> > fig = plt.figure() >> > ax1 = fig.add_subplot(111) >> > ax2 = ax1.twinx() >> > labels = ax2.yaxis.get_ticklabels() >> > [l.set_horizontalalignment('right') for l in labels] >> > labels[2].set_color('red') >> > labels[2].set_fontsize(20) >> > ax2.tick_params(pad=20) >> > ax1.plot(list(range(11))) >> > ax1.set_xlim(0,10) >> > ax2.set_ylim(0,10) >> > plt.show() >> > >> > I personally think that this level of control is very, very cool and one >> > of >> > the big selling points for MPL in general. >> > >> > Okay. If you want to set the alignment all the time, there might be a >> > way to >> > control this with matplotlibrc or style sheets: >> > http://matplotlib.org/users/customizing.html >> > http://matplotlib.org/users/style_sheets.html >> > However, I'm not the biggest fan of changing matplotlibrc. Mostly >> > because if >> > others try to reproduce your plots, they also need your rc file as well. >> > I >> > haven't used style sheets yet, but that might be a fix to this issue >> > (for me >> > at least). >> > >> > Hope that helps. >> > >> > Ryan >> > >> > On Sat, Feb 14, 2015 at 10:30 AM, Tommy Carstensen >> > wrote: >> >> >> >> Hi Ryan, >> >> >> >> Thanks for your answer. Sorry for not replying sooner. I fell asleep >> >> shortly after sending my question. >> >> >> >> What is "the OO way"? >> >> >> >> Your 1st sol
Re: [Matplotlib-users] horizontal alignment of a secondary y-axis
Again I did this padding manually by introducing yet another magic constant. Thank you to you and Erik for your help. After using a lot of hacks and magic constants here are the final plots: http://www.tommycarstensen.com/matplotlib1.png http://www.tommycarstensen.com/matplotlib2.png Notice 1) the right aligned secondary y-axis labels, 2) the non-overlapping ticks, 3) the padded secondary y-axis labels. I'm satisfied with this plot / not willing to spend any more time on it. Thank you for your help. On Sat, Feb 14, 2015 at 7:54 PM, Tommy Carstensen wrote: > Ryan, do you know, if there is any way I can make the padding > dependent on the tick label sizes? > for label in ax2.yaxis.get_ticklabels(): > label.set_horizontalalignment('right') > ax2.tick_params(pad=20) > > When the numbers are large, then they are glued to the secondary > y-axis. When they are small, then they are hovering far away from it. > > On Sat, Feb 14, 2015 at 7:20 PM, Ryan Nelson wrote: >> You're welcome, Tommy. I used gnuplot many years ago, but I've been much >> happier now that I know MPL. >> >> A gnuplot->MPL Rosetta Stone might be a useful blog post for someone. I >> haven't used gnuplot in so long that I don't think I could do this myself. >> >> R >> >> On Sat, Feb 14, 2015 at 12:28 PM, Tommy Carstensen >> wrote: >>> >>> Whoa, thanks for a great answer Ryan. I can see, why the level of >>> control MPL gives you is a great sales pitch. It's one of the reasons, >>> why I switched from gnuplot after using it for many years and making >>> many cool plots. The MPL learning curve has just been a bit steep, >>> when you are used to plot whatever you want. >>> >>> On Sat, Feb 14, 2015 at 5:06 PM, Ryan Nelson >>> wrote: >>> > Tommy, >>> > >>> > I'll try to answer your points in order: >>> > >>> > 1) Oops. That should have been "xticks". >>> > import matplotlib.pyplot as plt >>> > plt.plot([1,3,2]) >>> > ticks, labels = plt.xticks() >>> > plt.xticks(ticks, horizontalalignment='left') >>> > plt.show() >>> > >>> > >>> > 2) Sorry for the ambiguity. "OO" is short for object-oriented. There are >>> > two >>> > different approaches that people tend to use to make plots (although >>> > they >>> > can be mixed): 1) the "pyplot" way, which uses the pyplot wrapper >>> > functions >>> > and 2) the object-oriented way, which modifies the objects directly. >>> > This is >>> > what you did in your example where you snag the axes objects and operate >>> > on >>> > them directly. The "OO" way is ultimately more powerful, because the >>> > pyplot >>> > wrapper functions override some of your control. For example, because >>> > you >>> > want twin axes, you might not be able to use the pyplot.xticks function >>> > (Others, correct me if I'm wrong.), and you lose some fine control. See >>> > next >>> > example. >>> > >>> > 3) I know it *seems* like the for loop is an "ugly hack". However, you >>> > have >>> > to realize that this ultimately gives you a TON of control. Let's say, >>> > for >>> > example, that you wanted only one of the labels to be large and red to >>> > highlight a certain value. Using a modified version of your example, we >>> > get >>> > this: >>> > __ >>> > import matplotlib.pyplot as plt >>> > fig = plt.figure() >>> > ax1 = fig.add_subplot(111) >>> > ax2 = ax1.twinx() >>> > labels = ax2.yaxis.get_ticklabels() >>> > [l.set_horizontalalignment('right') for l in labels] >>> > labels[2].set_color('red') >>> > labels[2].set_fontsize(20) >>> > ax2.tick_params(pad=20) >>> > ax1.plot(list(range(11))) >>> > ax1.set_xlim(0,10) >>> > ax2.set_ylim(0,10) >>> > plt.show() >>> > >>> > I personally think that this level of control is very, very cool and one >>> > of >>> > the big selling points for MPL in general. >>> > >>> > Okay. If you want to set the alignment all the time, there might be a >>> > way to >>> > control this with matplotlibrc or style sheets: &