rgerum / pylustrator

Visualisations of data are at the core of every publication of scientific research results. They have to be as clear as possible to facilitate the communication of research. As data can have different formats and shapes, the visualisations often have to be adapted to reflect the data as well as possible. We developed Pylustrator, an interface to directly edit python generated matplotlib graphs to finalize them for publication. Therefore, subplots can be resized and dragged around by the mouse, text and annotations can be added. The changes can be saved to the initial plot file as python code.
GNU General Public License v3.0
707 stars 37 forks source link

Automatically changing ticks label font size #19

Closed ijpulidos closed 4 years ago

ijpulidos commented 4 years ago

For changing ticks label font size pylustrator is currently doing it manually tick by tick. For example if I want to change the tick font size to 14 and there are 8 ticks, I get something like the following:

plt.figure(1).axes[0].get_xaxis().get_major_ticks()[0].label1.set_fontsize(14)
plt.figure(1).axes[0].get_xaxis().get_major_ticks()[1].label1.set_fontsize(14)
...
plt.figure(1).axes[0].get_xaxis().get_major_ticks()[7].label1.set_fontsize(14)

I think this could be done programatically by looping through plt.figure(1).axes[0].get_xaxis().get_major_ticks() directly, then you can use the same pylustrator autogenerated code in many figures without having to manually edit the number of ticks by adding or removing lines. For example something like:

# Change major tick font size dynamically
for major_tick in plt.figure(1).axes[0].get_xaxis().get_major_ticks():
    major_tick.label1.set_fontsize(14)

should do it.

mmagnuski commented 4 years ago

That would be great - would improve pylustrator's output readibility a lot. When changing fontsize of both x and y ticklabels I get a wall of 18 lines of code, which could be 3 -4.

rgerum commented 4 years ago

Ok, I fixed this my setting the font properties directly in set_xticklabels. This makes it easier as the for loop in the generated code would make it more difficult when parsing in the automatically generated code (it needs to be parsed by pylustrator to know which changes where from pylustrator and which from the original code).