Skip to content

Commit bdf62ff

Browse files
blaiselcqalandefreitas
authored andcommitted
Add the option to make the legend transparent
This is useful when automatically generating a large number of plots, when the best legend position is not always the same.
1 parent 5d01eb3 commit bdf62ff

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

source/matplot/core/axes_type.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,7 @@ namespace matplot {
690690
// {{no}box { {linestyle | ls <line_style>}
691691
// | {linetype | lt <line_type>}
692692
// {linewidth | lw <line_width>}}}
693+
// {{no}opaque {fc <colorspec>}}
693694
include_comment("Axes legend");
694695
// Gnuplot version needs to be 5.2.6+ for keyentry
695696
bool ok = true;
@@ -753,7 +754,7 @@ namespace matplot {
753754
cmd += legend_->vertical() ? " vertical" : " horizontal";
754755
// text aligned to the left
755756
cmd += " Left";
756-
cmd += " opaque";
757+
cmd += legend_->opaque() ? " opaque" : " noopaque";
757758
cmd +=
758759
legend_->label_after_sample() ? " reverse" : " noreverse";
759760
cmd += legend_->invert() ? " invert" : " noinvert";

source/matplot/core/legend.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,4 +296,8 @@ namespace matplot {
296296
num_columns_ = 0;
297297
touch();
298298
}
299+
300+
bool legend::opaque() const { return opaque_; }
301+
302+
void legend::opaque(bool opaque) { opaque_ = opaque; };
299303
} // namespace matplot

source/matplot/core/legend.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ namespace matplot {
123123
void text_color(const color_array &text_color);
124124
template <class T> void text_color(T c) { text_color(to_array(c)); }
125125

126+
bool opaque() const;
127+
void opaque(bool opaque);
128+
126129
private:
127130
// The keys
128131
std::vector<std::string> strings_{};
@@ -150,6 +153,7 @@ namespace matplot {
150153
bool label_after_sample_{true};
151154
bool invert_{false};
152155
bool visible_{true};
156+
bool opaque_{true};
153157

154158
size_t num_columns_{0};
155159
size_t num_rows_{0};

0 commit comments

Comments
 (0)