1

I have not found a solution for this anywhere; I found many solutions where I can visualize an array by a picture of different colors;

However, I want something different: If I have an array, let's make it simple and I have

a=np.ones([3,3])

Then I want to export this matrix to a jpeg or png where the numpy array looks like a nice matrix from a paper or book, i.e. as it is written on LaTeX; so something you would get when compiling the command in LaTeX:

$a=\begin{pmatrix}1 & 1 & 1 \\\ 1 & 1 & 1 \\\ 1 & 1 & 1  \\\ \end{pmatrix}$

Is this possible?

2
  • Translation from a matrix into the expected latex command looks like a straightforward procedure. What seems to be a problem? Commented Mar 18, 2020 at 0:57
  • I thought that there is a way to directly get a picture of the matrix - I mean it does not need to look exactly like in LaTeX but I just wanted to give an idea of how it should look like approximately as for big matrices, the translation would get very tedious Commented Mar 18, 2020 at 1:03

1 Answer 1

1

You could use Matplotlib to plot your array as a table with plt.table. See the linked docs for options like colLabels for the column headers. Also, you'll probably want to modify the figure or the axes to adjust your image. For the following example, I have only turned off the axes with plt.axis("off").

import numpy as np
import matplotlib.pyplot as plt
data = np.random.randint(0, 1000, (5, 3))
plt.axis("off")
plt.table(cellText=data, colLabels=["A", "B", "C"], loc="center")
plt.savefig("data.png")

plot

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.