# Customize Tick Labels with Axis Artist

Hello all,

I need help to have customize tick labels using axis artist.
My problem is to create a grid representation in polar co-ordinates (see fig) with r = logspace(log(1),log(120),128)
and theta = linspace(0.17,2.97,64) # in radians

I managed to to create the proper gridlines. But unfortunately I have to remove the tick labels as the way I describe the grid locator they crowd the axis.
I would like to choose only certain points on the axis and label them as the plot would look nice.

Regards
Bhargav Vaidya.

Here is my code modified to my need from already existing code found in the web :

from matplotlib.transforms import Affine2D
import mpl_toolkits.axisartist.floating_axes as floating_axes

import numpy as np
import mpl_toolkits.axisartist.angle_helper as angle_helper
from matplotlib.projections import PolarAxes
from mpl_toolkits.axisartist.grid_finder import FixedLocator, MaxNLocator, \
DictFormatter

def setup_axes2(fig, rect):

tr = PolarAxes.PolarTransform()

pi = np.pi
theta = np.linspace(0.17,2.97,64) # Theta Co-ordinates
angle_ticks = [(0, r"$\frac{1}{2}\pi$"),
(.25*pi, r"$\frac{1}{4}\pi$"),
(.5*pi, r"$0$"),
(-.25*pi, r"$\frac{3}{4}\pi$"),
(-0.5*pi, r"$\pi$")]
grid_locator1 = FixedLocator([j-0.5*pi for j in theta])
#grid_locator1 = FixedLocator([v for v, s in angle_ticks])

grid_locator2 = FixedLocator([i for i in rad])

grid_helper = floating_axes.GridHelperCurveLinear(tr,
extremes=(.5*pi-0.17, -.5*pi+0.17, 120, 1),
grid_locator1=grid_locator1,
grid_locator2=grid_locator2,
tick_formatter1=None,
tick_formatter2=None,
)

ax1 = floating_axes.FloatingSubplot(fig, rect, grid_helper=grid_helper)

# create a parasite axes whose transData in RA, cz
aux_ax = ax1.get_aux_axes(tr)

aux_ax.patch = ax1.patch # for aux_ax to have a clip path as in ax
ax1.patch.zorder=0.9 # but this has a side effect that the patch is
# drawn twice, and possibly over some other
# artists. So, we decrease the zorder a bit to
# prevent this.

return ax1, aux_ax
if 1:
import matplotlib.ticker as mpltick
import matplotlib.pyplot as plt
fig = plt.figure(1, figsize=(10, 10))

ax2, aux_ax2 = setup_axes2(fig, 111)

ax2.axis["left"].major_ticklabels.set_visible(False)
ax2.axis["bottom"].major_ticklabels.set_visible(False)

ax2.grid(color='k',linestyle='-',linewidth=0.5)

plt.show()

Here is the eps file

Disk_grid.eps (190 KB)

There could be a few ways. What I recommend as a matter of fact is to
use other method to draw gridlines. On the other hand, given that you
have a working example, it could be better to have different axis to
draw ticklabels in locations where you want. Here is a diff.

Regards,

-JJ

*** qqwee2.py 2011-07-20 22:02:37.973960916 +0900
--- qqwee.py 2011-07-20 22:04:46.063960883 +0900

···

***************
*** 36,41 ****
--- 36,60 ----
ax1 = floating_axes.FloatingSubplot(fig, rect, grid_helper=grid_helper)

+ grid_locator1 = FixedLocator([j-0.5*pi for j in theta[::10]])
+ grid_locator2 = FixedLocator([i for i in rad[::5]])
+
+ grid_helper2 = floating_axes.GridHelperCurveLinear(tr,
+ extremes=(.5*pi-0.17,
-.5*pi+0.17, 120, 1),
+ grid_locator1=grid_locator1,
+ grid_locator2=grid_locator2,
+ tick_formatter1=None,
+ tick_formatter2=None,
+ )
+
+ ax1.axis["left2"] = grid_helper2.new_fixed_axis("left", axes=ax1)
+ ax1.axis["left2"].line.set_visible(False)
+ ax1.axis["left2"].toggle(ticks=False)
+
+ ax1.axis["bottom2"] = grid_helper2.new_fixed_axis("bottom", axes=ax1)
+ ax1.axis["bottom2"].line.set_visible(False)
+ ax1.axis["bottom2"].toggle(ticks=False)
+
# create a parasite axes whose transData in RA, cz
aux_ax = ax1.get_aux_axes(tr)

On Tue, Jul 12, 2011 at 2:12 AM, bhargav vaidya <coolastro@...287...> wrote:

Hello all,

I need help to have customize tick labels using axis artist.
My problem is to create a grid representation in polar co-ordinates (see fig) with r = logspace(log(1),log(120),128)
and theta = linspace(0.17,2.97,64) # in radians

I managed to to create the proper gridlines. But unfortunately I have to remove the tick labels as the way I describe the grid locator they crowd the axis.
I would like to choose only certain points on the axis and label them as the plot would look nice.

Regards
Bhargav Vaidya.

Here is my code modified to my need from already existing code found in the web :

from matplotlib.transforms import Affine2D
import mpl_toolkits.axisartist.floating_axes as floating_axes

import numpy as np
import mpl_toolkits.axisartist.angle_helper as angle_helper
from matplotlib.projections import PolarAxes
from mpl_toolkits.axisartist.grid_finder import FixedLocator, MaxNLocator, \
DictFormatter

def setup_axes2(fig, rect):

tr = PolarAxes.PolarTransform()

pi = np.pi
theta = np.linspace(0.17,2.97,64) # Theta Co-ordinates
angle_ticks = [(0, r"\\frac\{1\}\{2\}\\pi"),
(.25*pi, r"\\frac\{1\}\{4\}\\pi"),
(.5*pi, r"0"),
(-.25*pi, r"\\frac\{3\}\{4\}\\pi"),
(-0.5*pi, r"\\pi")]
grid_locator1 = FixedLocator([j-0.5*pi for j in theta])
#grid_locator1 = FixedLocator([v for v, s in angle_ticks])

grid_locator2 = FixedLocator([i for i in rad])

grid_helper = floating_axes.GridHelperCurveLinear(tr,
extremes=(.5*pi-0.17, -.5*pi+0.17, 120, 1),
grid_locator1=grid_locator1,
grid_locator2=grid_locator2,
tick_formatter1=None,
tick_formatter2=None,
)

ax1 = floating_axes.FloatingSubplot(fig, rect, grid_helper=grid_helper)

# create a parasite axes whose transData in RA, cz
aux_ax = ax1.get_aux_axes(tr)

aux_ax.patch = ax1.patch # for aux_ax to have a clip path as in ax
ax1.patch.zorder=0.9 # but this has a side effect that the patch is
# drawn twice, and possibly over some other
# artists. So, we decrease the zorder a bit to
# prevent this.

return ax1, aux_ax
if 1:
import matplotlib.ticker as mpltick
import matplotlib.pyplot as plt
fig = plt.figure(1, figsize=(10, 10))

ax2, aux_ax2 = setup_axes2(fig, 111)

ax2.axis["left"].major_ticklabels.set_visible(False)
ax2.axis["bottom"].major_ticklabels.set_visible(False)

ax2.grid(color='k',linestyle='-',linewidth=0.5)

plt.show()

Here is the eps file

------------------------------------------------------------------------------
All of the data generated in your IT infrastructure is seriously valuable.
Why? It contains a definitive record of application performance, security
threats, fraudulent activity, and more. Splunk takes this data and makes
sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-d2d-c2
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options