axes properties

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

axes properties

Jean-Philippe Grivet

Hello,

I have two questions related to axes in a 3-D plot.

1. I often find that ticks are too close together so that labels overlap.  How
can I change the number of ticks or the step length ?

2. The default axes lay-out has x increasing from left to right and y increasing
from front to back. My finction decrease quickly with increasing y, so that the
corresponding parts of the surface are hidden. Therefore, I would like to have
y values increasing from back to front. I understand that yaxis_invert can do it
but how is it used ?

Thank you for your help
Jean-Philippe


_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: axes properties

Amit Yaron
Try using the methods 'set_xticks', 'set_yticks' and 'set_zticks' of the
Axes object.
Each of them accepts a list of values that will be displayed.
For example:
   ax.set_xticks(np.r_[-10:10:3j])

Will display ticks for values -10,0 and 10 only.


On 11/03/17 19:54, Jean-Philippe GRIVET wrote:

> Hello,
>
> I have two questions related to axes in a 3-D plot.
>
> 1. I often find that ticks are too close together so that labels
> overlap.  How
> can I change the number of ticks or the step length ?
>
> 2. The default axes lay-out has x increasing from left to right and y
> increasing
> from front to back. My finction decrease quickly with increasing y, so
> that the
> corresponding parts of the surface are hidden. Therefore, I would like
> to have
> y values increasing from back to front. I understand that yaxis_invert
> can do it
> but how is it used ?
>
> Thank you for your help
> Jean-Philippe
>
>
>
> _______________________________________________
> Matplotlib-users mailing list
> [hidden email]
> https://mail.python.org/mailman/listinfo/matplotlib-users
>


_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: axes properties

vincent.adrien@gmail.com
Hello Jean-Philippe,

To complete Amit's reply and in case nobody else already answered your
other question, you can have a look at the following example (the output
is attached as a PDF) that shows:

- How to define tick locators, which can be useful for example when you
do not know in advance what exact values the ticks should have. Please
find more informations in the [official
docs](http://matplotlib.org/api/ticker_api.html). You may also find of
interest these recent examples, about:
    * [tick
locators](http://matplotlib.org/examples/ticks_and_spines/tick-locators.html);
    * [tick
formatters](matplotlib.org/examples/ticks_and_spines/tick-formatters.html);
- How to invert one of the axes (the z-axis in the example).

```python
import numpy as np
import matplotlib.pyplot as plt

from mpl_toolkits.mplot3d import Axes3D
from matplotlib.ticker import (LinearLocator, MaxNLocator,
                               MultipleLocator)


def dummy_plot(ax):
    X, Y = np.meshgrid(np.arange(-5, 5, 0.25), np.arange(-5, 5, 0.25))
    Z = np.sin(np.sqrt(X**2 + Y**2))
    ax.plot_surface(X, Y, Z, cmap='coolwarm')
    return ax

fig = plt.figure("Demo_Jean-Philippe_GRIVET", figsize=(4.8 * 3, 4.8))

ax0 = fig.add_subplot(1, 3, 1, projection='3d')
ax0 = dummy_plot(ax0)
ax0.set_title('Vanilla plot')

ax1 = fig.add_subplot(1, 3, 2, projection='3d')
ax1 = dummy_plot(ax1)
ax1.set_title('Custom locators')
ax1.set_xlabel('LinearLocator')  # evenly spaced ticks from min to max
ax1.xaxis.set_major_locator(LinearLocator(numticks=5))
ax1.set_ylabel('MaxNLocator')  # use up to nbins+1 ticks at nice locs
ax1.yaxis.set_major_locator(MaxNLocator(nbins=5, symmetric=True,
                                        integer=True))
ax1.set_zlabel('MultipleLocator')  # ticks/range are a multiple of base
ax1.zaxis.set_major_locator(MultipleLocator(base=0.4))

ax2 = fig.add_subplot(1, 3, 3, projection='3d')
ax2 = dummy_plot(ax2)
ax2.set_title('Inverted z-axis')
ax2.invert_zaxis()
# From looking at the code, it is equivalent to:
# bottom, top = ax2.get_zlim()
# ax2.set_zlim(top, bottom, auto=None)

plt.tight_layout()
plt.show()
```

Best,
Adrien

On 14/03/2017 16:43, Amit Yaron wrote:

> Try using the methods 'set_xticks', 'set_yticks' and 'set_zticks' of the
> Axes object.
> Each of them accepts a list of values that will be displayed.
> For example:
>   ax.set_xticks(np.r_[-10:10:3j])
>
> Will display ticks for values -10,0 and 10 only.
>
>
> On 11/03/17 19:54, Jean-Philippe GRIVET wrote:
>> Hello,
>>
>> I have two questions related to axes in a 3-D plot.
>>
>> 1. I often find that ticks are too close together so that labels
>> overlap.  How
>> can I change the number of ticks or the step length ?
>>
>> 2. The default axes lay-out has x increasing from left to right and y
>> increasing
>> from front to back. My finction decrease quickly with increasing y, so
>> that the
>> corresponding parts of the surface are hidden. Therefore, I would like
>> to have
>> y values increasing from back to front. I understand that yaxis_invert
>> can do it
>> but how is it used ?
>>
>> Thank you for your help
>> Jean-Philippe
>>
>>
>>
>> _______________________________________________
>> Matplotlib-users mailing list
>> [hidden email]
>> https://mail.python.org/mailman/listinfo/matplotlib-users
>>
>
>
> _______________________________________________
> Matplotlib-users mailing list
> [hidden email]
> https://mail.python.org/mailman/listinfo/matplotlib-users

_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users

Demo_Jean-Philippe_GRIVET.pdf (245K) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: axes properties

vincent.adrien@gmail.com
In reply to this post by Amit Yaron
Hello Jean-Philippe,

To complete Amit's reply and in case nobody else already answered your
other question, you can have a look at the following example (the output
is attached as a PDF) that shows:

- How to define tick locators, which can be useful for example when you
do not know in advance what exact values the ticks should have. Please
find more informations in the [official
docs](http://matplotlib.org/api/ticker_api.html). You may also find of
interest these recent examples, about:
    * [tick
locators](http://matplotlib.org/examples/ticks_and_spines/tick-locators.html);
    * [tick
formatters](matplotlib.org/examples/ticks_and_spines/tick-formatters.html);
- How to invert one of the axes (the z-axis in the example).

```python
import numpy as np
import matplotlib.pyplot as plt

from mpl_toolkits.mplot3d import Axes3D
from matplotlib.ticker import (LinearLocator, MaxNLocator,
                               MultipleLocator)


def dummy_plot(ax):
    X, Y = np.meshgrid(np.arange(-5, 5, 0.25), np.arange(-5, 5, 0.25))
    Z = np.sin(np.sqrt(X**2 + Y**2))
    ax.plot_surface(X, Y, Z, cmap='coolwarm')
    return ax

fig = plt.figure("Demo_Jean-Philippe_GRIVET", figsize=(4.8 * 3, 4.8))

ax0 = fig.add_subplot(1, 3, 1, projection='3d')
ax0 = dummy_plot(ax0)
ax0.set_title('Vanilla plot')

ax1 = fig.add_subplot(1, 3, 2, projection='3d')
ax1 = dummy_plot(ax1)
ax1.set_title('Custom locators')
ax1.set_xlabel('LinearLocator')  # evenly spaced ticks from min to max
ax1.xaxis.set_major_locator(LinearLocator(numticks=5))
ax1.set_ylabel('MaxNLocator')  # use up to nbins+1 ticks at nice locs
ax1.yaxis.set_major_locator(MaxNLocator(nbins=5, symmetric=True,
                                        integer=True))
ax1.set_zlabel('MultipleLocator')  # ticks/range are a multiple of base
ax1.zaxis.set_major_locator(MultipleLocator(base=0.4))

ax2 = fig.add_subplot(1, 3, 3, projection='3d')
ax2 = dummy_plot(ax2)
ax2.set_title('Inverted z-axis')
ax2.invert_zaxis()
# From looking at the code, it is equivalent to:
# bottom, top = ax2.get_zlim()
# ax2.set_zlim(top, bottom, auto=None)

plt.tight_layout()
plt.show()
```

Best,
Adrien

On 14/03/2017 16:43, Amit Yaron wrote:

> Try using the methods 'set_xticks', 'set_yticks' and 'set_zticks' of the
> Axes object.
> Each of them accepts a list of values that will be displayed.
> For example:
>   ax.set_xticks(np.r_[-10:10:3j])
>
> Will display ticks for values -10,0 and 10 only.
>
>
> On 11/03/17 19:54, Jean-Philippe GRIVET wrote:
>> Hello,
>>
>> I have two questions related to axes in a 3-D plot.
>>
>> 1. I often find that ticks are too close together so that labels
>> overlap.  How
>> can I change the number of ticks or the step length ?
>>
>> 2. The default axes lay-out has x increasing from left to right and y
>> increasing
>> from front to back. My finction decrease quickly with increasing y, so
>> that the
>> corresponding parts of the surface are hidden. Therefore, I would like
>> to have
>> y values increasing from back to front. I understand that yaxis_invert
>> can do it
>> but how is it used ?
>>
>> Thank you for your help
>> Jean-Philippe
>>
>>
>>
>> _______________________________________________
>> Matplotlib-users mailing list
>> [hidden email]
>> https://mail.python.org/mailman/listinfo/matplotlib-users
>>
>
>
> _______________________________________________
> Matplotlib-users mailing list
> [hidden email]
> https://mail.python.org/mailman/listinfo/matplotlib-users

_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users

Demo_Jean-Philippe_GRIVET.pdf (245K) Download Attachment
Loading...