0

I want to make a PDF of a question sheet. So I want to print a question, and then a block of empty grey boxes where the students fill in their answers.

I'm having trouble making the plot of empty grey squares. I thought one way to do it would be (1) to make a plot with some random data, (2) remove the data and the labels etc, (3) justify the plot so it stretches over the whole width of the page

This code:

import matplotlib.backends.backend_tkagg

import matplotlib
from matplotlib import pyplot as plt
import matplotlib.style
matplotlib.use("MacOSX")
time = [0,1,2,3] #dummy x axis
position = [0,100,200,300] # dummy y axis
plt.style.use('ggplot')
f = plt.figure()
plt.plot(time, position) #plot it
plt.xticks(time," ") #tried to remove the x-axis labels AND TICKS
plt.show()

The output is this

So I would know how to remove the y-axis words (plt.yticks,position, " ") but not how to remove the actual plot. The answers I've seen work elsewhere e.g. here don't seem to work.

Ideally can someone show me either (1) how to print a small (e.g. 1/6th of an A4 page) of grey squares to a PDF, or if not (2) how to actually remove the line from the below graph (doing plt.plot() also removed the grey squares).

I'm not sure if this would matter to the answer (i.e. combining text and picture?) but the ultimate aim would be for 4 strings, to print string, then empty grey boxes, string, empty grey boxes ; like a standard worksheet/exam paper style.

Slowat_Kela
  • 1,377
  • 2
  • 22
  • 60
  • 3
    Did you consider using latex to create a pdf with grey squares? That's sure a more naturaly way than using matplotlib for that matter. – ImportanceOfBeingErnest Apr 07 '19 at 21:26
  • 1
    Agree with @ImportanceOfBeingErnest, Latex is the right way to achieve this. Are you open to use LAtex instead of matplotlib? – amanb Apr 07 '19 at 23:46
  • Thank you both. I don't know latex, but I can see an example here that might be useful: https://www.overleaf.com/learn/latex/Typesetting%20exams%20in%20LaTeX. Before I learn it, I want to double check that this would be feasible: the bigger picture of my Q is I'm making a random question generator, so I need python to generate the questions, and I then write the questions in one PDF (with grey box space for answers) and then the working/answers in another PDF. Is it easy to go back and forth between python and latex (e.g. to create the random Qs in python and write to file with latex)? – Slowat_Kela Apr 08 '19 at 12:54

1 Answers1

0

Came up with this code that does what I want it to do, prints a block of empty grey squares:

time = [0,1,2,3,4,5,6,7,8,9]
position = [0,1,2,3,4,5,6,7,8,9]
plt.style.use('ggplot')
f = plt.figure(figsize=(30,10))
plt.plot(time, position,linestyle='None')
plt.xticks(time," ")
plt.yticks(position," ")
plt.tick_params(axis='both', which='both', bottom=False, top=False, labelbottom=False, right=False, left=False, labelleft=False)
Slowat_Kela
  • 1,377
  • 2
  • 22
  • 60