Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change font, and output an equilateral triangle #204

Closed
forgetmenot9911 opened this issue Apr 19, 2023 · 2 comments
Closed

change font, and output an equilateral triangle #204

forgetmenot9911 opened this issue Apr 19, 2023 · 2 comments

Comments

@forgetmenot9911
Copy link

Hello! Thanks for listening my issues.

  1. How can I change the font into another one, like Times New Roman?
  2. Can I get an equilateral triangle? I copied the given code, made some modifications, ran it, and got this:

test_triangle

my code is:

import ternary

scale = 40
figure, tax = ternary.figure(scale=scale)

# Draw Boundary and Gridlines
tax.boundary(linewidth=1.0)
tax.gridlines(color="grey", multiple=5)

# Set Axis labels and Title
fontsize = 12
offset = 0.14
# tax.set_title("Triangle Plot\n\n", fontsize=fontsize)
# tax.right_corner_label("X", fontsize=fontsize)
# tax.top_corner_label("Y", fontsize=fontsize)
# tax.left_corner_label("Z", fontsize=fontsize)
tax.left_axis_label("Left label", fontsize=fontsize, offset=offset)
tax.right_axis_label("Right label", fontsize=fontsize, offset=offset)
tax.bottom_axis_label("Bottom label", fontsize=fontsize, offset=offset)

# Draw lines parallel to the axes
tax.horizontal_line(16)
tax.left_parallel_line(10, linewidth=2., color='red', linestyle="--")
tax.right_parallel_line(20, linewidth=3., color='blue')

# Draw an arbitrary line, ternary will project the points for you
p1 = (22, 8, 10)# bottom, right, left
p2 = (2, 22, 16)
tax.line(p1, p2, linewidth=3., marker='*', color='purple', linestyle=":")

tax.ticks(axis='lbr', multiple=5, linewidth=1, offset=0.025)
tax.get_axes().axis('off')
tax.clear_matplotlib_ticks()
# tax.show()
tax.savefig('test_triangle.png',dpi=600)
@bmondal94
Copy link

  1. Font setting:
    a. You can change the font in global setting (more here)
import matplotlib.pyplot as plt
plt.rcParams["font.family"] = "Times New Roman" 

Make sure the font is available in your system. To check the available font family in your python environment

import matplotlib
print(matplotlib.font_manager.get_font_names())

b. If you want to change the font locally. Pass the font name by kwargs.

tax.left_axis_label("Left label", fontsize=fontsize, offset=offset, fontdict={'fontname':'Go'})
  1. Equilateral triangle:
    Add this at the end
tax.get_axes().set_aspect(1)

This issue was discussed here: #171 (comment)

@forgetmenot9911
Copy link
Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants