Closed charlesll closed 3 years ago
Also, I am trying to have the axis labels horizontal. I tried:
ax.set_rlabel('To Al$_2$O$_3$', rotation = 'horizontal')
but this does not work. Am I missing something or is that a bug?
Thank you @charlesll for using my code! Regarding your questions, does the below solves your problems?
import matplotlib.pyplot as plt
import mpltern
ax = plt.subplot(projection='ternary')
ax.set_tlabel('Top')
ax.set_llabel('Left')
ax.set_rlabel('Right')
ax.taxis.set_label_rotation_mode('horizontal')
ax.laxis.set_label_rotation_mode('horizontal')
ax.raxis.set_label_rotation_mode('horizontal')
ax.raxis.set_ticks([]) # remove only ticks
# ax.raxis.set_visible(False) # remove both ticks and labels
plt.savefig('test.pdf')
Please also refer to: https://mpltern.readthedocs.io/en/latest/gallery/axis_and_tick/axis_label_rotation.html
If I remember correctly, rotation
was disabled by default because it might not give a positioning we usually want. If you would like to control by yourself, please do ax.raxis.set_label_rotation_mode('manual')
, and hopefully ax.set_rlabel('Right', rotation='horizontal')
may work. (Actually, in the example above, this might give a better looking.)
Thanks for your answer ! It clarifies most of the things I was wondering about :)
The only thing I would like to do now : is it possible to remove the horizontal line at the bottom of the diagram too ?
I just noticed something : the Left label is not at the same vertical position as the Right label... Do you know how this could be solved ?
I just noticed something : the Left label is not at the same vertical position as the Right label... Do you know how this could be solved ?
Hacked this by using annotate() instead of label().
is it possible to remove the horizontal line at the bottom of the diagram too ?
Yes; please use ax.spines
as below. The tside
indicates the edge opposite to the top corner (similarly we have lside
and rside
in ax.spines
).
import matplotlib.pyplot as plt
import mpltern
ax = plt.subplot(projection='ternary')
ax.raxis.set_label_rotation_mode('manual')
ax.set_tlabel('Top', rotation=0)
ax.set_llabel('Left', rotation=0)
ax.set_rlabel('Right', rotation=0)
# ax.raxis.set_ticks([]) # remove only ticks
ax.raxis.set_tick_params(color=(0, 0, 0, 0), labelcolor=(0, 0, 0, 0))
ax.spines['tside'].set_visible(False)
ax.taxis.set_label_rotation_mode('horizontal')
ax.laxis.set_label_rotation_mode('horizontal')
ax.raxis.set_label_rotation_mode('horizontal')
plt.savefig('test4.png')
Thank you also for notifying the vertical alignment inconsistency for left and right labels, when no ticks. By default, I maybe implemented them to have positions not to overlap with tick labels. This however eventually also shows the dependence on if we have tick labels or not.
If a pragmatic solution is OK, one way might be to make tick labels of bottom to transparent, as also implemented above (ax.raxis.set_tick_params(color=(0, 0, 0, 0), labelcolor=(0, 0, 0, 0))
).
Otherwise, so far the best solution is to have new annotation text, as you already found.
@yuzie007 thanks, works like a charm ! This does a nice diagram :)
Hi,
I am trying to remove the line marking the bottom X axis (raxis in mpl terminology) for one of my diagrams. I tried various things like but did not get anything to work.
Is that possible ? Is their anything like plt.axis('off') to set one of the axis off ?
Thanks in advance, Best, Charles.